private boolean tryEnqueueAttempt ( DelayedExecution < T > delayedExecution ) { int rejectionThreshold = queueRejectionThreshold . get ( ) ; if ( rejectionThreshold < 0 ) { return requestQueue . offer ( delayedExecution ) ; } long stamp = stampedLock . readLock ( ) ; try { while ( requestQueue . size ( ) < rejectionThreshold ) { long writeStamp = stampedLock . tryConvertToWriteLock ( stamp ) ; if ( writeStamp != 0L ) { stamp = writeStamp ; return requestQueue . offer ( delayedExecution ) ; } else { stampedLock . unlock ( stamp ) ; stamp = stampedLock . writeLock ( ) ; } } return false ; } finally { stampedLock . unlock ( stamp ) ; } }
enqueue the attempt into our underlying queue . since it s expensive to dynamically resize the queue we have a separate rejection threshold which if less than 0 is ignored but otherwise is the practical cap on the size of the queue .