public boolean acquire ( int capacity ) { if ( capacity < 0 ) { throw new IllegalArgumentException ( "capacity to acquire cannot be negative" ) ; } if ( availableCapacity < 0 ) { return true ; } synchronized ( lock ) { if ( availableCapacity - capacity >= 0 ) { availableCapacity -= capacity ; return true ; } else { return false ; } } }
Attempts to acquire a given amount of capacity . If acquired capacity will be consumed from the available pool .