I need to interrupt swingworkers, but if the thread is running some fragment, it should interrupt after that. Something like this:
public class worker extends SwingWorker<Integer, String>{
//(...) constructors and everything else
protected Integer doInBackground() throws Exception{
//Code that can be interrupted
while(true){
//(...) more code that can be interrupted
//This shouldn't be interrupted, has to wait till the loop ends
for(int i=0; i<10; i++){
//(...) more code that can be interrupted
}
}
}
Interrupting the worker with:
Worker worker = new Worker();
worker.execute();
worker.cancel(true);
I've tried synchronized blocks, but not sure if that doesn't work or i'm just doing it wrong.
Is there a way? Thanks!