Code example for ReadWriteLock

Methods: writeLock

0
		super(); 
		this.units = initial;
	} 
 
	public void add(long quantity) throws InterruptedException  {
		lock.writeLock().lock();
		try { 
			units += quantity;
		} finally { 
			lock.writeLock().unlock();
		} 
	} 
	 
	public void reduce(long quantity) throws InterruptedException {
		add(-quantity);
	} 
 
	public long getUnits() throws InterruptedException { 
		lock.readLock().lockInterruptibly();
		try { 
			return units;