public void run() {
while (true) {
if (Thread.currentThread().isInterrupted()) {
return;
}
// do something
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
如果线程任务是这种形式,使用thread.Interrupt 的方法来打断thread, 从而结束该thread的生命周期。
温馨提示:内容为网友见解,仅供参考