I usually run my program with about 4 threads and anywhere between 1 hour to 10 hours after the program is running some threads just stop and do nothing, I have my program around Exception and Throwable block and I also have a uncaughtException for the thread and nothing gets added to my log files about any errors. How can I find what is causing the threads to stop?
EDIT
Here is the basic structure of my code
Below is the code for setting the uncaughtException block
newThread.setName("Thread" + totalNumberOfThreads);
newThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException(Thread t, Throwable e)
{
Main.logger.info("ERROR! An exception occurred in " + t.getName() + ". Cause: " + e.getMessage());
}
});
newThread.start();
And this is the basic structure of the thread
@Override
public void run()
{
while (true)
{
try
{
//a long section of code
}
catch (Exception e)
{
e.printStackTrace();
Main.logger.info(threadName + ": " + e);
}
catch (Throwable t)
{
Main.logger.info(threadName + ": " + "Throwable: " + t);
}
finally
{
//some code to close connections.. ect..
}
} // end while
}
How can I find what is causing the threads to stop?
Do you know for a fact that the threads have stopped? As mentioned they might be blocked. You can use either jstack to see if they are active or for closer inspection start the program with remote debugging enabled and attach a debugger when you feel they have stopped.
You could try running the program in a debugger, which would let you inspect the state of the threads.
You can also use the built-in Ctrl-Break or Ctrl-\mechanism in Java - see Troubleshooting Hanging or Looping Processes, which will cause the HotSpot VM to print a thread dump, including thread state.
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