私は通常、約4つのスレッドでプログラムを実行し、プログラムが実行されてから1時間から10時間後に、いくつかのスレッドが停止して何もしません。例外と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
}