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