java--Multithreading Management (concurrent package)

Source: Internet
Author: User

First on the two picture, the left one is the concurrent under the package of all the interface, the right is all the classes under the package, in fact, we often use the interface and classes are a few, the next will be described in detail.

1. Common interfaces

Callable: A thread interface with a return value

Future: A generic interface used to receive the return value, providing an operation that cancle the terminating thread

Executor: Performer of specific runnable tasks

Executorservice: A thread pool manager that can dispatch runnable and callable tasks

Blockingqueue: Blocking queues

2. Common Classes

(1) Executors: The operation used to create the thread pool

Executors.newfixedthreadpool (n): Create a fixed-size thread pool

Executors.newcachedthreadpool (): Create a thread-free pool that automatically recycles and exploits idle (over 60s unused) threads

Executors.newsinglethreadexecutor (): a single background thread that ensures that individual tasks are executed in order, and that no multiple threads are active at the same time.

(2) Semaphore: A statistical semaphore used to limit the number of threads that can access certain resources.

Use the Acquire () function to consume a resource

Use the release () function to release a resource

Not to be continued ....

java--Multithreading Management (concurrent package)

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.