Multithreading-executor,executors,executorservice,scheduledexecutorservice,abstractexecutorservice

Source: Internet
Author: User

Reference

The cost of the system to start a new thread is relatively high because it involves interacting with the operating system. Using a thread pool can improve performance, especially if you need to consider using thread pooling when you want to create a lot of short-lived threads in your program. The thread pool creates a large number of idle threads at system startup, the program passes a Runnable object or callable object to the thread pool, and the thread pool initiates a thread to execute their run () or call () methods, and when the run () or call () method finishes executing, The thread does not die, but returns to the thread pool again to become idle, waiting to execute the next Runnable object's run () or call () method.

The thread pool can also effectively control the number of concurrent threads in the system, and when the system contains a large number of concurrent threads, it can cause severe system performance degradation or even a JVM crash, while the thread pool's maximum number of threads parameter controls the number of concurrent threads in the system.

JAVA5 thread Pool

Java5 built-in thread pool, the Executors factory class was added to generate the thread pool, which contains several static factory methods to create the threading pools.

Executorservice Newcachedthreadpool () creates a buffer-capable thread pool

Executorservice Newfixedthreadpool (int n) creates a reusable thread pool with a fixed number of threads

Executorservice Newsinglethreadexecutor () Create a thread pool that is single thread, same as Newfixedthreadpool (1)

Scheduledexecutorservice newscheduledthreadpool (int corepoolsize) creates a thread pool with the specified number of threads, which can perform the threading task after a specified delay.

Scheduledexecutorservice Newsinglethreadscheduledexecutor () creates a thread pool with only one number of threads, which can perform thread tasks after a specified delay.

The executorservice represents a thread pool that executes threads as soon as possible (thread tasks are performed as long as there are idle thread pools in the pool of threads).

Scheduledexecutorservice represents a thread pool that can execute thread tasks after a specified delay or periodically.

Multithreading-executor,executors,executorservice,scheduledexecutorservice,abstractexecutorservice

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.