void runTask ( PolicyTaskFutureImpl < ? > future ) { running . add ( future ) ; // intentionally done before checking state to avoid missing cancels on shutdownNow int runCount = runningCount . incrementAndGet ( ) ; try { Callback callback = cbLateStart . get ( ) ; if ( callback != null ) { long delay = future . nsQueueEnd - future . nsAcceptBegin ; if ( delay > callback . threshold && cbLateStart . compareAndSet ( callback , null ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "callback: late start " + delay + "ns > " + callback . threshold + "ns" , callback . runnable ) ; globalExecutor . submit ( callback . runnable ) ; } } callback = cbConcurrency . get ( ) ; if ( callback != null && runCount > callback . threshold && cbConcurrency . compareAndSet ( callback , null ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "callback: concurrency > " + callback . threshold , callback . runnable ) ; globalExecutor . submit ( callback . runnable ) ; } if ( state . get ( ) . canStartTask ) { future . run ( ) ; } else { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , "Cancel task due to policy executor state " + state ) ; future . nsRunEnd = System . nanoTime ( ) ; future . cancel ( false ) ; if ( future . callback != null ) future . callback . onEnd ( future . task , future , null , true , 0 , null ) ; // aborted, queued task will never run } } catch ( Error x ) { // auto FFDC } catch ( RuntimeException x ) { // auto FFDC } finally { runningCount . decrementAndGet ( ) ; running . remove ( future ) ; } }
Invoked by the policy executor thread to run a task .