Various thread pool implementations, pool

Source: Internet
Author: User

List several thread pool implementations:

[1] executorservice

Http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ExecutorService.html

[2] scheduledexecutorservice

Http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ScheduledExecutorService.html

[3] threadpoolexecutor

Http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ThreadPoolExecutor.html

[4] scheduledthreadpoolexecutor

Http://www.gznc.edu.cn/yxsz/jjglxy/book/Java_api/java/util/concurrent/ScheduledThreadPoolExecutor.html

 

 

public static void main(String[] args) {

 

// Create a thread pool that can reuse a set of fixed threads and run these threads in a shared unbounded queue mode.

    ExecutorService pool1 = Executors.newFixedThreadPool(3);

    

// Create a thread pool where new threads can be created as needed, but they will be reused when previously constructed threads are available

    ExecutorService pool2 = Executors.newCachedThreadPool();

 

// Create an executor that uses a single worker thread and runs this thread in the unbounded queue mode.

    ExecutorService pool3 = Executors.newSingleThreadExecutor();

 
// Create a thread pool, which can be scheduled to run commands after a given delay or regularly run

    ScheduledExecutorService pool4 = Executors.newScheduledThreadPool(3);
 

// Create a single-threaded execution program, which can be scheduled to run commands after a given delay or regularly run

    ScheduledExecutorService pool5 = Executors.newSingleThreadScheduledExecutor();

 

// Create a scalable Thread Pool

    ThreadPoolExecutor pool6 = new ThreadPoolExecutor(3, 5, 3,

            TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(3), new ThreadPoolExecutor.DiscardOldestPolicy());

 

// Create a scalable thread pool that can be scheduled to run commands after a given delay or regularly run

    ScheduledThreadPoolExecutor pool7 = new ScheduledThreadPoolExecutor(5);

    

}

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.