我的问题很简单。我有几个线程,但一个随机中断。谁打断了它?
如何找到我的应用程序(或可能在库中)中断我的线程的位置?
程序中没有任何明确的interrupt()
。
[edit]我无法共享大量代码,因为它是一个庞大的专有系统,并且可以在整个地方进行调用。我认为大部分内容都可以概括在这里(从我的脑海中):
public void run() {
while (true) {
sendReceive();
try{ Thread.sleep(500); } catch (InterruptedException ex) {}
}
}
public void sendReceive() {
synchronized(stringBuilder) {
out.write("data to send\n");
startReceiving();
stringBuilder.wait();
System.out.println(stringBuilder.toString());
}
}
public void startReceiving() {
new Thread(new Runnable() {
public void run() {
synchronized (stringBuilder) {
String s;
while ((s = in.readLine()) != null) { stringBuilder.append(s); }
stringBuilder.notifyAll();
}
}
}).start();
}
它在stringBuilder.wait();
中被中断,导致弹出窗口说通信错误。在通信日志中,我看到发送数据的两个事件,只收到一个数据,如下所示:
Sent: "Get status\n"
Received: "1231"
Sent: "Get status\n"
Received: "632"
Sent: "Get status\n" <-- interrupt happens after this, but thread continues.
Sent: "Get status\n"
Received: "3568903"
Sent: "Get status\n"
Received: "6"
...
我没有使用任何线程池。