The art of Java concurrent programming

Source: Internet
Author: User
Tags cas

CAS has two features:

1. For loop

2, Compareandset (possibly other threads change and then reset, at this time the CAS is successful, that is, the process of CAs execution, it is possible for multiple threads to modify this variable, rather than the individual thread mutually exclusive modification )

3, CAs and mutexes are different, CAs can be successfully executed by multiple threads at the same time.

Thread.Join ()

Here is the source code. A.jonin (b), so when B ends, it notifya, How does it happen ? Implementation is within the JVM, need to look at the JVM source code

Thread.Join ()

while (T.isalive ()) {

Wait (0);

}

Viii. concurrency tool Classes in Java (provides overloaded methods such as timeouts, including interfaces for querying thread queuing and statistics)

1, Countdownlatch

1. Cannot be reused

2, equivalent to Thread.Join ()

3. Call the Countdown method Happens-before, and another thread calls the await method.

2, Cyclicbarrier

1, can be used for multiple threads to calculate data, and finally consolidate the results of the scene.

2. The thread that merges the results of the calculation is the one that was last await.

3, you can reset the counter in the process of await

4, can query whether there is an await thread broken

3, Semaphore

1. The number of threads used to control access to a resource

4. Exchange

1, for the data exchange between threads.

2. There is a synchronization point between the two threads for data exchange on the synchronization point.

The art of Java concurrent programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.