Code example for Semaphore

Methods: acquire, release

0
	 *           wait has interrupted 
	 */ 
	public static <V> V executeSequencially(final Semaphore semaphore, final boolean wait, final Callable<V> callable) {
		if (wait) {
			try { 
				semaphore.acquire();
			} catch (final InterruptedException e1) {
				return null; 
			} 
		} else if (!semaphore.tryAcquire())
			return null; 
		try { 
			return callable.call();
		} catch (final Throwable e) {
			throw new RuntimeException("Exception in sequencial part", e);
		} finally { 
			semaphore.release();
		} 
	} 
}