javadoc for ExecutorService sometimes refers to the case where Thread terminates "due to a failure." However, it is not clear to which failure this applies.
For example, the single thread executor documentation states that
if this single thread terminates due to a run-time failure before shutting down, a new one will take its place if necessary to complete subsequent tasks
I would think that such a situation could happen in the event of an exception or maybe a RuntimeException , but it does not seem to be so. Executing the following code seems to give the same stream name and stream identifier.
ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(() -> { System.out.println("Hello from " + Thread.currentThread().getName()+ " " + Thread.currentThread().getId()); throw new NullPointerException("Test"); }); executor.submit(() -> { System.out.println("Hello 2 from " + Thread.currentThread().getName() + " " + Thread.currentThread().getId()); });
The output of this code is:
Hello from pool-1-thread-1 12 Hello 2 from pool-1-thread-1 12
It seems that the same thread is reused even in the case of a NullPointerException .
So what is the “failure” for Javadoc?
source share