Part 8: java. util. concurrent-& quot; Executors & quot;

Source: Internet
Author: User
Tags terminates

Today in this article we will see some of threads pool available in "Executors" Factory-
Public static ExecutorService
NewFixedThreadPool (int nThreads)
Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. at any point, at most nThreads threads will be active processing tasks. if additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. if any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks. the threads in the pool will exist until it is explicitly shutdown.

Public static ScheduledExecutorService
NewScheduledThreadPool (int corePoolSize)
Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.

Public static ExecutorService newCachedThreadPool ()
Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. these pools will typically improve the performance of programs that execute implements short-lived asynchronous tasks. callto execute will reuse previusly constructed threads if available. if no existing thread is available, a new thread will be created and added to the pool. threads that have not been used for sixty seconds are terminated and removed from the cache. thus, a pool that remains idle for long enough will not consume any resources. note that pools with similar properties but different details (for example, timeout parameters) may be created using ThreadPoolExecutor constructors.

 

Public static ExecutorService newSingleThreadExecutor ()
Creates an Executor that uses a single worker thread operating off an unbounded queue. (Note however that if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks .) tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time. unlike the otherwise equivalent newFixedThreadPool (1) the returned executor is guaranteed not to be rewritable able to use additional threads.

Public static ExecutorService newSingleThreadExecutor ()
Creates an Executor that uses a single worker thread operating off an unbounded queue. (Note however that if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks .) tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time. unlike the otherwise equivalent newFixedThreadPool (1) the returned executor is guaranteed not to be rewritable able to use additional threads.


Author: silence is gold

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.