0
いつ接続が中断されたかを判断しようとしていますが、私にとってはランダムに発生します。私は、接続を凍結するかどうかを示すタイマーを設定しようとしましたが(私の場合、接続を使用する各タスクは2秒以上かかることはありません)、動作していないようです。Java:凍結または切断された場合のdb接続を再開するにはどうすればいいですか?
また、いくつかの種類のタスクを実行している複数のスレッドが同時に実行されているかどうか、スレッドがまだ生きているかどうか、割り込まれていない場合、私には、接続の問題があることを示しています。ここで
は私がやっていることの要点である:表ロックがあるとき
public void run(){
super.run();
try {
Timer timer = new Timer(true);
TimerTask task = new TimerTask(){
@Override
public void run() {
if(isAlive() || interrupted()){//there is a problem with the connection, but I never enter this case...
interrupt();
timer.cancel();
//end the connection and restart it all over again
try {
conn.close();
restartConnection();
} catch (SQLException e) {
e.printStackTrace();
}
}
else{//there is no problem with the connection
}
}
};
timer.schedule(task, 5000);//each task should not take anywhere near 5 secs, if it does, then I THINK there is a connection problem
timer.cancel();
}
} catch (IOException e) {
e.printStackTrace();
}
}