1, the polling isTerminated:
while (!service.isTerminated()) {
TimeUnit.SECONDS.sleep(1);
}
2, the polling awaitTermination:
while (!service.awaitTermination(1, TimeUnit.SECONDS)) {
}
It represents a service thread pool object when the thread pool out of the while loop will automatically terminate. The principle of these two methods is actually the same. I am here to set up a poll once every 1s, you can control the polling interval as small as possible, in order to promptly respond to the logic thread pool after termination. Since both methods are blocked, so do not forget to interrupt exception handling.
Java thread creation and termination 3 ways to create threads 1. Inherit the Thread class 2. Implement the Runnable interface 3. Use Callable and Future 3 ways to terminate threads 1. Use the stop met...
The thread will be ended normally after the thread is executed, and it will be destroyed after the thread is over, but the Run () method will never end, or the time required to cycle, when the thread ...
Termination of thread The method of thread pauses in Java is the Sleep method, and the SLEEP method is a static method of the Thread class. The following is in the form of code, using the SLEEP method...
Java termination thread method 1. STOP () method for Thread instance object This method allows thread to throw out the ireths of Error ThreadDeath abnormally to violent termination thread, threaddeath...
[Thread pool, Lambda expression] Chapter One Waiting for Wake Up Mechanism 1.1 Inter-thread communication concept: Multiple threads are processing the same resource, but the processing actions (thread...
———— There are usually two execution methods of thread pool: execute and submit, so what is the difference between them? ———— Is there any way to stop t...
Termination thread pool execution First, the closure and termination of the difference between thread pool 1. Thread pool close 2. Thread pool termination Second, the termination thread pool execution...
In the Java platform, each object can assume the function of a lock because of the built-in lock mechanism. The Java virtual machine maintains two "queues" for each object (let's call it a &...
Thread pool tools: Test category: Results of the:...