Code example for ReentrantReadWriteLock

Methods: readLock, writeLock

0
package lock2synchronized; 
 
import java.util.concurrent.locks.Lock; 
import java.util.concurrent.locks.ReentrantReadWriteLock; 
 
public class Lock2Synchronized { 
	private final static ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
    private final static Lock r = rwl.readLock();
    private final static Lock w = rwl.writeLock();
     
    private static int account = 1000;
	 
	public static void main(String[] args) {
		Thread[] personlist = new Thread[100];
		Runnable person = new Runnable(){
			public void run(){ 
				w.lock();
				try{ 
					System.out.println(Thread.currentThread().getName()+"'s account = " + account+" before depost");
					account+=1000;
					System.out.println(Thread.currentThread().getName()+"'s account = " + account+" after depost\n");
				}finally{