![](/img/trans.png)
[英]How can I interrupt RestTemplate call as soon as my thread is interrupted?
[英]How can I find where was my thread interrupted?
我可能無意中更改了項目中的某些內容。 現在,一個關鍵線程在不應該被中斷時會被中斷,而isInterrupted
在線程應該運行時會返回true。
因為沒有人會為我找到問題,所以我正在尋求有關查找問題的方法的幫助。 我需要找到:
因為IDE工具和調試器可能會在搜索中發揮作用,所以我會補充說我正在使用NetBeans IDE。
您可以在中斷堆棧時記錄堆棧的特殊線程下運行它:
// A simple process.
class Process implements Runnable {
@Override
public void run() {
try {
while (true) {
Thread.sleep(1000L);
}
} catch (InterruptedException ex) {
System.out.println("Interrupted");
}
}
}
public void test() throws InterruptedException {
Thread t = new Thread(new Process()) {
@Override
public void interrupt() {
// Log a stack trace when iterrupted.
new Exception("Where the hell did that come from!").printStackTrace(System.out);
// Pass it up the chain.
super.interrupt();
}
};
t.start();
Thread.sleep(2048);
t.interrupt();
t.join();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.