Code example for Semaphore

Methods: availablePermits, release

0
			disposeConnection(pconn);
			return; } 
		if (activeConnections <= 0) {
			throw new AssertionError(); }
		activeConnections--;
		semaphore.release();
		recycledConnections.add(pconn);
		assertInnerState();  
	} 
 
	private synchronized void disposeConnection (PooledConnection pconn) {
		pconn.removeConnectionEventListener(poolConnectionEventListener);
		if (!recycledConnections.remove(pconn)) {
			// If the PooledConnection is not in the recycledConnections list, 
			// we assume that the connection was active. 
			if (activeConnections <= 0) {
				throw new AssertionError(); }
			activeConnections--;
			semaphore.release(); }
		closeConnectionAndIgnoreException(pconn);
		assertInnerState();  
	} 
 
	private void closeConnectionAndIgnoreException (PooledConnection pconn) {
		try { 
			pconn.close(); }
		catch (SQLException e) {
			log("Error while closing database connection: "+e.toString()); }
	} 
 
	private void log (String msg) {
		String s = "MiniConnectionPoolManager: "+msg;
		try { 
			if (logWriter == null) {
				System.err.println(s); }
			else { 
				logWriter.println(s); }}
		catch (Exception e) {System.err.println(e);}
	} 
 
	private void assertInnerState() { 
		if (activeConnections < 0) {
			throw new AssertionError(); }
		if (activeConnections + recycledConnections.size() > maxConnections) {
			throw new AssertionError(); }
		if (activeConnections + semaphore.availablePermits() > maxConnections) {
			throw new AssertionError(); }
	} 
 
	private class PoolConnectionEventListener implements ConnectionEventListener {
		public void connectionClosed (ConnectionEvent event) {