Code example for Lock

Methods: newCondition

0
		} 
		 
	} 
	 
	static Lock lock = new ReentrantLock();
	static Condition c = lock.newCondition();
	 
	static ReadWriteLock rwLock = new ReentrantReadWriteLock();
	 
	static volatile int counter;
	 
	static class Reader implements Runnable {
 
		@Override 
		public void run() { 
			Lock readLock = rwLock.readLock();
			while(!Thread.interrupted()) {
				 
				readLock.lock();
				try { 
					System.out.println("I have a lock!" + Thread.currentThread().getName() + " " + counter);