Java Concurrency Programming Practice reading Notes (3) Task execution

Source: Internet
Author: User

Similar to the multi-tasking scenario of a Web server, it is not possible to use only one thread to provide services externally. This way, efficiency and throughput are too low.

However, it is not possible to create a thread with a single request because the cost of creating the thread is very high and the number of threads that the system can create is limited.

So the executor appeared.

The meaning of executor frame thread pool

Thread creation too little wasted server resources, in addition to the creation of more threads and the server is very tired. Two extreme results are not on the external throughput.

So threads need to be managed uniformly, not casually new thread (). Start ().

Executor provides a pool of four threads.

Executorservice management functions

Include: Close and force shut down, shut down, interrupt, wait for interruption, submit task, bulk submit task.

Find out what you can use for parallelism

If multiple tasks can be parallel, it's best to parallel it:

In general, parallelism of heterogeneous tasks with large execution times is meaningless, and execution time is limited to the task that takes the longest time to execute:

In this case, the consideration is to break down the Taska.

Executorcompletionservice can submit tasks in batches and get execution results;

Java Concurrency Programming Practice reading Notes (3) Task execution

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.