About Executors.newfixedthreadpool when to create a new thread

Source: Internet
Author: User

Executors.newfixedthreadpool is meant to create a fixed-size thread pool, but what does this thread pool do?

1, when a task commits execution, it will first determine whether the number of thread pool has reached the upper limit, if not create a new thread to perform the task, even if the original created thread is idle and will not be used. See Source:

    private boolean addifundercorepoolsize (Runnable firsttask)  {         Thread t = null;         final ReentrantLock mainLock = this.mainLock;         mainlock.lock ();        try {             if  (poolsize < corepoolsize & & runstate == running)                  t = addthread (Firsttask);         } finally {             Mainlock.unlock ();        }         if  (T == nuLL)             return false;         t.start ();         return true ;     }

A new thread is created as long as the thread pool is not full, and no new threads are created because other threads of the thread pool are idle

About Executors.newfixedthreadpool when to create a new thread

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.