我通常用大约 4 个线程运行我的程序,并且在程序运行后 1 小时到 10 小时之间的任何地方,一些线程只是停止并且什么也不做,我的程序围绕 Exception 和 Throwable 块,我也有一个线程的 uncaughtException 并且什么都没有被添加到我的日志文件中关于任何错误。如何找到导致线程停止的原因?
编辑
这是我的代码的基本结构
下面是设置 uncaughtException 块的代码
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();
这是线程的基本结构
@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
}