This issue has come up in a distributed-multithreaded application I'm developing, where threads can appear to randomly return during distributed task execution. Assume that every thread in this application uses the same basic code as the block below:
public class ExecutionThread extends Thread{
@Override
public void run(){
while(true){
try{
//task submitter app dumps all Tasks in to a queue. We retrieve
//those tasks here one-by-one and run them:
Task t = priorityBlockingQueue.take();
//execute is abstract, so it could potentially do anything here:
t.execute();
} catch(Throwable e){
//task submitter app will be able to access the Throwable later:
t.setUncaughtThrowable(e);
}
}
}
}
I should note that the Task class is abstract and very simplistic - it only has the execute() method which is abstract, so I didn't feel it necessary to post the code for it here.
I know that some crazy things can happen in the JVM, but this code to me seems fairly bulletproof, in that the thread should never return unless the JVM it's running in dies. In actuality, we're seeing threads still return without their respective JVMs dying and can't pin down the cause. To make matters worse, we can't see the console for these threads because they are being spawned as child processes on remote machines. We've tried logging the throwable, but nothing gets printed to file. Any ideas on what might still cause this thread to return?
There must be an Exception in the catch clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With