My problem is simple. I have several threads, but one gets interrupted at random. Who interrupted it?
How do I find out where in my application (or perhaps in a library) my thread gets interrupted?
There is no explicit interrupt()
anywhere in the program.
[edit] I can't share much code because it's a large proprietary system and calls jump all over the place. I think most of it can be summarized here (out of my head):
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();
}
It gets interrupted in stringBuilder.wait();
causing a popup saying communication error. In the communication log I see two events of the data being sent, and only one data received, like this:
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"
...
I'm not using any thread pooling.