1. class AtomicReferenceArray<E>

public class AtomicReferenceArray<E>extends Objectimplements Serializable

The object reference array of its elements can be updated atomically

2. Constructor details

AtomicReferenceArray

public AtomicReferenceArray(int length)
Create a new... Of a given length AtomicReferenceArray.

Parameters :
length - The length of the array

AtomicReferenceArray

public AtomicReferenceArray(E[] array)
Creates a new... With the same length as the given array AtomicReferenceArray, And copies all its elements from the given array .

Parameters :
array - An array from which to copy elements
Throw out :
NullPointerException - If the array is null

3. Methods,

length

public final int length()
Returns the length of the array .

return :
The length of the array

get

public final E get(int i)
To obtain position i The current value of the .

Parameters :
i - Indexes
return :
Current value

set

public final void set(int i,
E newValue)
Place i Is set to the given value .

Parameters :
i - Indexes
newValue - The new value

lazySet

public final void lazySet(int i,
E newValue)
Finally, the location will be i Is set to the given value .

Parameters :
i - Indexes
newValue - The new value
Start with :
1.6

getAndSet

public final E getAndSet(int i,
E newValue)
Place it in an atomic way i Is set to the given value , And return the old value .

Parameters :
i - Indexes
newValue - The new value
return :
Previous value

compareAndSet

public final boolean compareAndSet(int i,
E expect,
E update)
If the current value == Expected value , Then the position will be changed in the form of atoms i Is set to the given update value .

Parameters :
i - Indexes
expect - Expected value
update - The new value
return :
If it works , Then return to true. return false Indicates that the actual value is not equal to the expected value .

weakCompareAndSet

public final boolean weakCompareAndSet(int i,
E expect,
E update)
If the current value == Expected value , Then the position will be changed in the form of atoms i Is set to the given update value .

Probably Unexpected failure And there's no sort guarantee , So it's almost just compareAndSet An appropriate replacement for .

Parameters :
i - Indexes
expect - Expected value
update - The new value
return :
If it works , Then return to true.

toString

public String toString()
Returns the string representation of the current value of an array .

Cover :
class Object Medium toString
return :
The string representation of the current value of an array .

java Concurrent programming : Thread safety management class -- Atomic operation class --AtomicReferenceArray<E> More articles about

  1. java Concurrent programming Thread basis

    java Concurrent programming Thread basis 1. java Multithreading in java It's naturally multithreaded , You can start a main Method , see main How many threads are started at the same time when the method is started public class OnlyMain { ...

  2. Java Concurrent programming | Thread pool details

    original text : https://chenmingyu.top/concurrent-threadpool/ Thread pool Thread pool is used to process asynchronous tasks or concurrent tasks advantage : Reuse created threads , Reduce creation and destruction of threads ...

  3. Java Concurrent programming : Inter thread communication wait、notify

    Java Concurrent programming : Two ways to collaborate between threads :wait.notify.notifyAll and Condition We've talked a lot about synchronization before , But in reality , You need collaboration between threads . For example, the most classic producers - consumer ...

  4. Java Concurrent programming : Creation of threads and processes ( turn )

    Java Concurrent programming : How to create threads ? The origin of processes and threads has been described in the previous article , Let's talk about it today Java How to create threads , Let the thread perform a subtask . Let's talk about Java Application and process related conceptual knowledge in , ...

  5. java Concurrent programming | Thread details

    Personal website :https://chenmingyu.top/concurrent-thread/ Processes and threads process : When the operating system runs a program, it will create a process for it ( For example, a java Program ), Process is resource allocation ...

  6. java Concurrent Programming Series 2 : Atomic manipulation /CAS

    What is atomic operation An operation or series of operations that cannot be interrupted The way to do atomic operations Java It can be done by locking and looping CAS Atomic operations can be realized in different ways CAS( Compare And Swap )   Why would there be CAS? Compar ...

  7. Java Concurrent programming —— The use of thread pools

    In the previous article , When we use threads, we create a thread , It's very easy to implement , But there will be a problem : If the number of concurrent threads is large , And each thread executes a short task and ends , In this way, creating threads frequently will greatly reduce the cost of the system ...

  8. Java Concurrent programming —— Thread pool

    The outline of this article : One .Java Medium ThreadPoolExecutor class Two . In-depth analysis of thread pool implementation principle 3、 ... and . Examples of use Four . How to reasonably configure the size of thread pool One .Java Medium ThreadPoolExecutor class ...

  9. Java Concurrent programming ( 3、 ... and )Thread The use of the class

    One . State of thread Thread from creation to final death , There are several States to go through . Generally speaking , Threads include the following states : establish (new). be ready (runnable). function (running). Blocking (blocked).time wait ...

  10. [ turn ]JAVA Concurrent programming learning notes Unsafe class

    1. adopt Unsafe Class can allocate memory , Can free up memory : Class 3 A local way allocateMemory.reallocateMemory.freeMemory They are used to allocate memory , Expanding and freeing memory , And C language ...

Random recommendation

  1. java aes_cbc_256 Encryption and decryption

    Before that, we were in Beijing openssl Shanghe ios We tested them on the Internet AES256 position cbc Encryption and decryption of patterns Use today java Provided api Let's test it : And then make sure that PC,iOS, Encryption and decryption of data on three Android platforms : 1. First of all ...

  2. xvfb start-up PyQt4 Procedure Report Unable to load library icui18n error

    xvfb start-up PyQt4 The program reported the following error : Unable to load library icui18n "Cannot load library icui18n: (libicui18n.so ...

  3. Swing How to make dialogues

    There are two types of dialog: modal non-modal: must use JDialog directly Taken JFileChooser as Exam ...

  4. Java--&gt;IO Stream simulation realizes user login and login information

    --> Test Test class package com.dragon.java.hwlogin; import java.io.FileNotFoundException; import java.u ...

  5. UISlider Use

    UISlider It's a slider for adjustment , You can set some properties of the program through the slider Construction method :     imgSlider = [[UISlider alloc] initWithFrame:sliderRect ...

  6. UVALive4513 Stammering Aliens( Hashifa , The suffix array )

    Topic link :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12580 [ Ideas ] The number of occurrences is not less than k The longest overlapable substring and the last occurrence of times ...

  7. Walk into Node.js And HTTP Implementation analysis

    author : Zhenglong ( hj Web Front-end development engineer ) This is an original article , Please indicate the author and source of reprint Above, " Walk into Node.js The boot process " We've got a good start . since Node.js Our strength is to handle network requests , Then we ...

  8. The first 63 section :Java Medium Spring MVC Introduction notes

    Preface thank ! Thanks to take care of ~ Java Medium Spring MVC Introduction notes MVC brief introduction Spring MVC Basic concepts Spring MVC Project structures, maven Use Spring MVC Development Realize data binding ...

  9. HDOJ 4267 A Simple Problem with Integers ( Line segment tree )

    subject : Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

  10. About Runtime.getRuntime().exec() It's blocking 2 Trap

    This article is from Netease cloud community background Believe in doing java Children's shoes developed on the server side , Come across Java Applications call external commands to start some new processes to perform some operations , At this time, we will use Runtime.getRuntime().exec(), ...