calling shutdown () in the pool means that the pool will no longer accept a new task for execution, but the current ones will work without interruption.
calling awaitTermination (timeout) holds the calling thread until the pool ends, but if the timeout is reached, the current thread will issue execption, but it will not affect the tasks in the pool.
If your runnable throws an unused exception when starting a thread pool, then this runnable is no longer in a run state - the thread pool usually does not refer to such an object.
If you use FixedThreadPool, then this pool will create as many threads as you like, and will not stop them until you call shutdown () in this pool.
Unless you have a reference to the runnable object that threw the exception, it behaves like a regular unpublished object that will be garbage collected.
if you call shutdown () and then wait for Termination () in the thread pool, and your program does not stop anyway, this means that not all instances of your runnable throw an exception, and some still work, blocking the pool from full completion .
In java, you cannot kill or stop a thread from starting in the same way (you can only kill an entire JVM using, for example, System.exit(0) , but not just select a thread), if you need such functionality, you need to program the runnable body in a way that allows you to somehow exchange with it, i.e. using some variable " volatile boolean " and that it will respond to a change in the value of this variable - this means that you need to add "if it checks" the value of this variable in the body of the run () method, which will return when it is.
source share