final void tryTerminate2(){
  for (; ; ) {
    int c=ctl.get();
    int rs=runStateOf(c);
    if (rs < SHUTDOWN || rs == TERMINATED || (rs == SHUTDOWN && !workQueue.isEmpty()))     return;
    if (workerCountOf(c) != 0) {
      interruptIdleWorkers(ONLY_ONE);
      return;
    }
    if (ctl.compareAndSet(c,ctlOf(TERMINATED,0))) {
      mainLock.lock();
      try {
        termination.signalAll();
      }
  finally {
        mainLock.unlock();
      }
      terminated();
      return;
    }
  }
}

final void tryTerminate2 ( ) { for ( ; ; ) { int c = ctl . get ( ) ; int rs = runStateOf ( c ) ; if ( rs < SHUTDOWN || rs == TERMINATED || ( rs == SHUTDOWN && ! workQueue . isEmpty ( ) ) ) return ; if ( workerCountOf ( c ) != 0 ) { interruptIdleWorkers ( ONLY_ONE ) ; return ; } if ( ctl . compareAndSet ( c , ctlOf ( TERMINATED , 0 ) ) ) { mainLock . lock ( ) ; try { termination . signalAll ( ) ; } finally { mainLock . unlock ( ) ; } terminated ( ) ; return ; } } }
transitions to terminated state if either ( shutdown and pool and queue empty ) or ( stop and pool empty ) . if otherwise eligible to terminate but workercount is nonzero , interrupts an idle worker to ensure that shutdown signals propagate . this method must be called following any action that might make termination possible - - reducing worker count or removing tasks from the queue during shutdown . the method is non - private to allow access from scheduledthreadpoolexecutor .
