@ Deprecated protected Runnable getTask ( boolean oldThread ) throws InterruptedException { // PK77809 long waitTime ; Runnable r = null ; boolean firstTime = true ; while ( true ) { synchronized ( this ) { // System.out.println("1 " + activeThreads + " : " + poolSize_); if ( firstTime ) { -- activeThreads ; // PK77809 Let the buffer know we have a waiting thread if ( oldThread ) { requestBuffer . incrementWaitingThreads ( ) ; } } if ( poolSize_ > maximumPoolSize_ ) { // Cause to die if too many threads if ( ! growasneeded || ! firstTime ) { // System.out.println("2 die"); -- poolSize_ ; // PK77809 Let the buffer know we have a waiting thread requestBuffer . decrementWaitingThreads ( ) ; return null ; } } // infinite timeout if we are below the minimum size waitTime = ( shutdown_ ) ? 0 : ( poolSize_ <= minimumPoolSize_ ) ? - 1 : keepAliveTime_ ; } // PK27301 start try { r = ( waitTime >= 0 ) ? ( Runnable ) ( requestBuffer . poll ( waitTime ) ) : ( Runnable ) ( requestBuffer . take ( ) ) ; } catch ( InterruptedException e ) { ++ activeThreads ; // PK77809 Let the buffer know we have a waiting thread synchronized ( this ) { requestBuffer . decrementWaitingThreads ( ) ; } ; throw e ; } // PK27301 end synchronized ( this ) { // System.out.println("3 r=" + r); if ( r == null ) { r = ( Runnable ) requestBuffer . poll ( 0 ) ; } if ( r != null ) { ++ activeThreads ; break ; } else if ( poolSize_ > minimumPoolSize_ ) { // discount the current thread // System.out.println("4 die"); poolSize_ -- ; // PK77809 Signal the buffer we have removed a thread requestBuffer . decrementWaitingThreads ( ) ; break ; } // System.out.println("going again"); } firstTime = false ; } return r ; }
Get a task from the handoff queue or null if shutting down .