Java and the threadpoolexecutor of the contract

Source: Internet
Author: User

Overview

Threadpoolexecutor as a java.util.concurrent package to provide the basis for external implementation, in the form of internal thread pool to provide management task execution, thread scheduling, thread pool management and other services.

Construction parameters

Corepoolsize the number of core threads. Maximumpoolsize the maximum number of threads. KeepAliveTime Maximum survival time. Unit time units. Workqueue blocks the task queue. Threadfactory new Thread Factory. Handler when the number of submitted tasks exceeds the sum of Maxmumpoolsize+workqueue, the task is assigned to Rejectedexecutionhandler to handle.

1. When the thread pool is less than corepoolsize, the new commit task creates a new thread to perform the task, even if there are idle threads in the thread pools.

2. When the thread pool reaches corepoolsize, the new commit task is put into Workqueue, waiting for the task to be scheduled to execute in the thread pool

3. When Workqueue is full and maximumpoolsize>corepoolsize, the new commit task creates a new thread to perform the task

4. When the number of submitted tasks exceeds maximumpoolsize, the new submission task is handled by Rejectedexecutionhandler

5. When the thread pool exceeds the corepoolsize thread and the idle time reaches KeepAliveTime, the idle thread is closed

6. When setting Allowcorethreadtimeout (true), corepoolsize thread idle time in the thread pool reaches KeepAliveTime will also close

 PublicThreadpoolexecutor (intCorepoolsize,intMaximumpoolsize,LongKeepAliveTime, timeunit unit, Blockingqueue<Runnable>WorkQueue, Threadfactory threadfactory, Rejectedexecutionha Ndler handler) {if(Corepoolsize < 0 | |maximumpoolsize<= 0 | |maximumpoolsize< Corepoolsize | |KeepAliveTime< 0)            Throw Newillegalargumentexception (); if(WorkQueue = =NULL|| Threadfactory = =NULL|| Handler = =NULL)            Throw NewNullPointerException ();  This. corepoolsize =corepoolsize;  This. maximumpoolsize =maximumpoolsize;  This. WorkQueue =WorkQueue;  This. KeepAliveTime =Unit.tonanos (KeepAliveTime);  This. Threadfactory =threadfactory;  This. Handler =handler; }

Java and the threadpoolexecutor of the contract

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.