public void release ( int capacity ) { if ( capacity < 0 ) { throw new IllegalArgumentException ( "capacity to release cannot be negative" ) ; } // in the common 'good' case where we have our full capacity available we can // short circuit going any further and avoid unnecessary locking. if ( availableCapacity >= 0 && availableCapacity != maxCapacity ) { synchronized ( lock ) { availableCapacity = Math . min ( ( availableCapacity + capacity ) , maxCapacity ) ; } } }
Releases a given amount of capacity back to the pool making it available to consumers .