I have method to stop eclipse job thread which is called after button is clicked:
public void stop(final Task task){
for (TaskWrapperJob job : jobsList){
if (job.getTask().id().equals(task.id())){
job.getThread();
if (!Thread.interrupted()) {
try {
job.getThread().interrupt();
} catch (Exception e) {
e.printStackTrace();
}
}
finished(task, TaskResult.stopped());
jobsList.remove(job);
break;
}
}
}
And have class which extends Job class:
private class TaskWrapperJob extends Job {
private final Task task;
private final StatusController status;
private TaskWrapperJob(final Task task, final StatusController status) {
super(task.name());
this.task = task;
this.status = checkNotNull(status);
}
private Task getTask(){
return task;
}
@Override protected IStatus run(final IProgressMonitor monitor) {
started(task);
logger.info("AFTER START");
final TaskResult result = runTask();
logger.info("BEFORE END");
finished(task, result);
return Status.OK_STATUS;
}
private TaskResult runTask() {
try {
return task.execute(status);
} catch (final Throwable e) {
return TaskResult.failed("Uncought exception during execution", e);
}
}
}
Why when job.getThread().interrupt is called, task.execute(status) is still running?
I make logger.info(...) in execute method too and it shows that there is the same thread.
How should I stop job?
Thanks for help.