如何令java线程池中线程超过5分钟时该线程自杀

如题所述

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的生命周期。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答