Code example for Semaphore

Methods: release, tryAcquire

0
 
	/** 
	 * Cancel an in-progress prompt. 
	 */ 
	public void cancelPrompt() { 
		if (!promptToken.tryAcquire()) {
			// A thread has the token, so try to interrupt it 
			response = null;
			promptResponse.release();
		} else { 
			// No threads have acquired the token 
			promptToken.release();
		} 
	} 
}