final void tryTerminate(){
  for (; ; ) {
    int c=ctl.get();
    if (isRunning(c) || runStateAtLeast(c,TIDYING) || (runStateOf(c) == SHUTDOWN && !workQueue.isEmpty()))     return;
    if (workerCountOf(c) != 0) {
      interruptIdleWorkers(ONLY_ONE);
      return;
    }
    final ReentrantLock mainLock=this.mainLock;
    mainLock.lock();
    try {
      if (ctl.compareAndSet(c,ctlOf(TIDYING,0))) {
        try {
          terminated();
        }
  finally {
          ctl.set(ctlOf(TERMINATED,0));
          termination.signalAll();
        }
        return;
      }
    }
  finally {
      mainLock.unlock();
    }
  }
}

final void tryTerminate ( ) { for ( ; ; ) { int c = ctl . get ( ) ; if ( isRunning ( c ) || runStateAtLeast ( c , TIDYING ) || ( runStateOf ( c ) == SHUTDOWN && ! workQueue . isEmpty ( ) ) ) return ; if ( workerCountOf ( c ) != 0 ) { interruptIdleWorkers ( ONLY_ONE ) ; return ; } final ReentrantLock mainLock = this . mainLock ; mainLock . lock ( ) ; try { if ( ctl . compareAndSet ( c , ctlOf ( TIDYING , 0 ) ) ) { try { terminated ( ) ; } finally { ctl . set ( ctlOf ( TERMINATED , 0 ) ) ; termination . signalAll ( ) ; } return ; } } finally { mainLock . unlock ( ) ; } } }
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 .
