I'm trying to run a thread until a mouse event occurs, which will trigger an interrupt to the thread. The problem is that I can't get the thread to stop running in an asynchronous way (i.e. to listen is a mouse event occurred). Instead, what happens is that the thread never exits the while loop. This is what I have so far:
private class aListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
if(condition){
aThread.run();
}
else{
aThread.interrupt();
}
}
}
...
private class workThread extends Thread {
private volatile Thread blinker;
public void run() {
blinker = new Thread();
blinker.run();
Thread thisThread = Thread.currentThread();
System.out.print(Thread.currentThread());
while (true){
try {
doSomething();
Thread.sleep(1000);
} catch (InterruptedException e) {
blinker = null;
return;
}
}
}
}