Code example for Semaphore

Methods: acquireUninterruptiblyavailablePermitsrelease

0
	} 
 
	protected void waitForProcessingToComplete(final int index) {
		final Semaphore s = semaphores[index];
		// Early-out: start-up or handler has finished processing 
		if ( s.availablePermits() == 0 ) {
			// This will block until handler has finished processing 
			s.acquireUninterruptibly();
			// Give the permit back 
			s.release();
		} 
 
		postProcess(index);
		processingState.set(index, false);
	} 
 
	protected abstract void postProcess(int index);
 
}