@ -94,9 +96,9 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -94,9 +96,9 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
privatebooleancancelled=false;// within activeThreads synchronization
/**
@ -271,7 +273,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -271,7 +273,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
*@see#close()
*/
publicbooleanisActive(){
returnthis.active;
return!this.closed.get();
}
/**
@ -309,14 +311,15 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -309,14 +311,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
@ -326,7 +329,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -326,7 +329,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@ -386,12 +389,13 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -386,12 +389,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);
}
@ -416,9 +420,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -416,9 +420,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");
}
}
@ -463,9 +470,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -463,9 +470,12 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@ -474,27 +484,19 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
@@ -474,27 +484,19 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator