public int setMaximumConcurrentRequests ( int newMax ) { if ( newMax < 1 ) { throw new IllegalArgumentException ( "Maximum concurrent requests must be at least 1" ) ; } int oldMax = this . max ; this . max = newMax ; if ( newMax > oldMax ) { synchronized ( this ) { while ( ! queue . isEmpty ( ) ) { int oldVal , newVal ; do { oldVal = requests ; if ( oldVal >= max ) { return oldMax ; } newVal = oldVal + 1 ; } while ( ! requestsUpdater . compareAndSet ( this , oldVal , newVal ) ) ; SuspendedRequest res = queue . poll ( ) ; res . exchange . dispatch ( res . next ) ; } } } return oldMax ; }
Set the maximum concurrent requests . The value must be greater than or equal to one .