@ -96,9 +98,9 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -96,9 +98,9 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
privatebooleancancelled=false;// within activeThreads synchronization
/**
@ -274,7 +276,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -274,7 +276,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
*@see#close()
*/
publicbooleanisActive(){
returnthis.active;
return!this.closed.get();
}
/**
@ -312,14 +314,15 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -312,14 +314,15 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
publicvoidexecute(Runnabletask,longstartTimeout){
Assert.notNull(task,"Runnable must not be null");
if(!isActive()){
thrownewTaskRejectedException(getClass().getSimpleName()+" has been closed already");
thrownewTaskRejectedException(getClass().getSimpleName()+" is not active");
// Release concurrency permit if thread creation fails
@ -329,7 +332,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -329,7 +332,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@ -405,12 +408,13 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -405,12 +408,13 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
*/
@Override
publicvoidclose(){
if(this.active){
this.active=false;
if(this.closed.compareAndSet(false,true)){
Set<Thread>threads=this.activeThreads;
if(threads!=null){
if(this.cancelRemainingTasksOnClose){
this.cancelled=true;
synchronized(threads){
this.cancelled=true;
}
// Early interrupt for remaining tasks on close
threads.forEach(Thread::interrupt);
}
@ -435,9 +439,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -435,9 +439,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
}
}
privatevoidcheckCancelled(){
if(this.cancelled){
thrownewTaskRejectedException(getClass().getSimpleName()+" has cancelled all remaining tasks");
if(this.cancelled){// within synchronization from TaskTrackingRunnable
if(future!=null){
future.cancel(false);
}
thrownewCancellationException(getClass().getSimpleName()+" has cancelled all remaining tasks");
}
}
@ -477,9 +484,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -477,9 +484,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@ -488,27 +498,19 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -488,27 +498,19 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator