Java thread pool [go]

Source: Internet
Author: User

Executor is a top-level interface in which only one method execute (Runnable) is declared, the return value is void, the argument is of type Runnable,

The literal meaning can be understood, is used to carry out the mission;

Then the Executorservice interface inherits the executor interface and declares some methods: Submit, InvokeAll, Invokeany and shutdown, etc.

Abstract class Abstractexecutorservice implements the Executorservice interface, which basically implements all the methods declared in Executorservice;

Then Threadpoolexecutor inherits the class Abstractexecutorservice.

executors The following static methods are available in this tool class:

    • Executors.newCachedThreadPool () infinite size thread pool, threads are automatically reused
    • Executors.newfixed ThreadPool (int) thread pool to fix the number of threads
    • Executors.newsingle threadexecutor () mono-thread Actuator

According to several factory methods in the Executors class, respectively, the following are used:

    • Linkedblockingqueue. Fixedthreadpool and Singlethreadexecutor Use this blockingqueue, the queue length is unbounded, and is suitable for submitting tasks that are independent of each other's dependent scenarios.
    • Synchronousqueue. Cachedthreadpool uses this blockingqueue, which usually requires the thread pool not to set the maximum number of threads to ensure that the submitted task will be executed without being discarded. This is usually a scenario that is suitable for tasks that depend on each other.

Of course, developers can also customize Threadpoolexecutor when using arrayblockingqueue bounded queues

Java thread pool [go]

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.