private void release ( long sessionId , int releasePermits ) { increaseAvailable ( releasePermits ) ; holders . computeIfPresent ( sessionId , ( id , acquired ) -> { acquired -= releasePermits ; if ( acquired <= 0 ) { return null ; } return acquired ; } ) ; checkAndNotifyWaiters ( ) ; }
Release permits and traverse the queue to remove waiters that meet the requirement .