Java Concurrent Package Common class summary

Source: Internet
Author: User

Concurrent package is commonly used multi-threaded related packages, recently because of the development of SDN program, for multi-threaded use more than before, is a simple summary.

The first class of atomic class: a situation in which multiple threads work together to manipulate a count

Atomiclong

Atomicinteger

Type II Lock and condition

Condition is obtained from lock, so in use, after the execution of Lock.lock () condition operation, condition commonly used two methods await and signal.

It is common to use multiple threads to manipulate a common resource, and one thread can execute a situation after the end of execution by another thread.

In addition, lock should replace the previous synchronized keyword. The synchronized is a synchronization policy at the JVM level that is allocated and freed by the JVM for locks. However, it is said that high concurrency requires frequent switching of line stacks and poor performance.

From now on, you should use lock for synchronization in your code.

The third kind of multi-threaded task execution Executorservice

This section is largely about three concepts,

Callable executed task executor perform task () The return data of the future asynchronous commit task Futuretask for the specific implementation

Thread resources are precious resources of the system, and indeed it should not be the programmer's random new thread way to start the thread themselves. If the project has its own framework, you should use the threading tools in the project framework if there is no best use of the Executorservice tool class provided by the JDK.

Common thread pool

    1. Executorservice Cachedthreadpool = Executors.newcachedthreadpool (); --Timeout destroys the thread in the pool
    2. Executorservice Fixedthreadpool = Executors.newfixedthreadpool (3); --Threads in the thread pool are not destroyed even when they are idle
    3. Executorservice Singlethreadpool = Executors.newsinglethreadexecutor ();
    4. Scheduledexecutorservice Scheduledthreadpool = Executors.newscheduledthreadpool (3)--a thread pool capable of performing tasks on a timed basis, For example, can be used in the data collection function, every hour to execute

Class Fourth Tool class

such as Cyclicbarrier, Countdownlatch is used to coordinate multiple threads, execute sequential

Class fifth thread-safe collection classes such as Blockingqueue Concurrentmap

Java Concurrent Package Common class summary

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.