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