Code example for Semaphore

Methods: releasetryAcquire

0
		return tryBorrowEntry(true); 
	} 
	 
	@Override 
	public PoolEntry<T> tryBorrowEntry(boolean createNew) throws PoolException {
		boolean acquireSuccess = borrowingSemaphore.tryAcquire();
		if (!acquireSuccess) {
			return null; 
		} 
		 
		return innerBorrowEntry(createNew);
	} 
	 
	private PoolEntry<T> innerBorrowEntry(boolean createNew) throws PoolException {
		try { 
			PoolEntry<T> entry = idleEntries.poll();
			if (entry == null && createNew) {
				entry = createIdleEntry();
			} 
			 
			if (entry == null) {
				borrowingSemaphore.release();
			} 
			return entry;
		} catch (Exception e) {
			borrowingSemaphore.release();
			throw new PoolException(e);
		} 
	} 
 
	private PoolEntry<T> createIdleEntry() throws Exception { 
Contextual code suggestions in your IDE  Get Codota for Java