And look back on the 20th day of Java

Source: Internet
Author: User

Thread pool

The thread pool can improve the performance of the program, which creates a large number of idle threads at the start of the program, the program can give the runnable or callable implementation class objects to the thread pool, and the thread pool frees up an idle thread to execute the Run method of the implementation class object. When the Run method finishes executing, the thread returns to the idle state. Programs can also reduce the burden of excessive threading on system performance by setting the number of thread pool threads to control the number of concurrent threads in the system

To perform a thread task using a thread pool:

① calls the static factory method of the executors class to create a Executorservice object that represents a thread pool
② Create a runnable or callable implementation class object to perform a task on behalf of a thread
③ invokes the Submit method of the Executorservice object to submit a runnable instance or callable instance
④ calls the Executorservice Shutdown method Shutdownnow method to close the thread pool, the shutdown method executes the submitted task, and the Shutdownnow method pauses the processing of the awaited task, attempting to stop the task that is being performed

And look back on the 20th day of Java

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.