do not use interruptions to abort execution
This commit is contained in:
@@ -12,8 +12,19 @@ public class AbortException extends RuntimeException {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public static ThreadLocal<JobAborter> IS_CANCELLED = new ThreadLocal<>();
|
||||
|
||||
public static void setAborter(final JobAborter jobAborter) {
|
||||
IS_CANCELLED.set(jobAborter);
|
||||
}
|
||||
|
||||
public static void cancel() {
|
||||
IS_CANCELLED.get().cancel();
|
||||
}
|
||||
|
||||
public static void abortIfInterrupted() throws AbortException {
|
||||
if (Thread.interrupted()) {
|
||||
final JobAborter aborter = IS_CANCELLED.get();
|
||||
if (aborter != null && Boolean.TRUE.equals(IS_CANCELLED.get().isCancelled())) {
|
||||
throw new AbortException();
|
||||
}
|
||||
}
|
||||
|
||||
13
pdb-api/src/main/java/org/lucares/pdb/api/JobAborter.java
Normal file
13
pdb-api/src/main/java/org/lucares/pdb/api/JobAborter.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.lucares.pdb.api;
|
||||
|
||||
public class JobAborter {
|
||||
private boolean isCancelled = false;
|
||||
|
||||
public void cancel() {
|
||||
isCancelled = true;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user