public T getIdleRunner ( long idleTime ) { // Take the first runner QueueItem < T > item = queue . poll ( ) ; // All runners might be currently in use, which is fine in this case. if ( item == null ) { return null ; } // If the runner wasn't idle for the expected time, we need to put it back to the queue (it will be added to the // begging again). if ( ( System . currentTimeMillis ( ) - item . timestamp ) < idleTime ) { queue . add ( item ) ; return null ; } // Otherwise we do have runner that hasn't been used for at least idleTime, so we can return it now return item . runner ; }
Return a runner that haven t been used at least for the configured number of milliseconds .