Code example for Semaphore

Methods: acquire, release

0
	static int count=0;
	private static Semaphore semaphore= new Semaphore(3);
	private static CyclicBarrier cyclicBarrier=new CyclicBarrier(2);
	@Override 
	public Connection call() throws Exception {
		semaphore.acquire();
		Connection con=JDBCUtil.getConnection();
		count++;
		System.out.println("waitin");
		cyclicBarrier.await();
		semaphore.release();
		System.out.println("released");
		return con;
	} 
	public void closeConnection(Connection con){
		try { 
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}