古いコードを改訂すると、私は遭遇しました。次のケースで割り込みの代わりにisInterruptedを使用する方が良いでしょう
public void stop() {
if (this.simulationThread != null) {
this.simulationThread.interrupt();
try {
this.simulationThread.join();
}
catch (InterruptedException exp) {
log.error(null, exp);
}
this.simulationThread = null;
}
}
public void run() {
while (!Thread.interrupted() && simulationThread == Thread.currentThread()) {
}
}
私は不思議に思っていました、使用するのが良いでしょうか、それとも重要ではありませんか?
public void run() {
Thread t = Thread.currentThread();
// Will it better to use isInterrupted, since it will not clear the interrupt
// flag?
while (!t.isInterrupted() && simulationThread == t) {
}
}