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
}
Do you know for a fact that the threads have stopped? As mentioned they might be blocked. You can use either
jstackto 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.