Mercurial > hg > Members > shoshi > TreeCMSv2
view src/treecms/test/ReentrantLockTest1.java @ 25:c1e7ec6b3d44
commit
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Jul 2011 14:39:35 +0900 |
parents | |
children |
line wrap: on
line source
package treecms.test; import java.io.IOException; import java.util.concurrent.locks.ReentrantLock; public class ReentrantLockTest1 { public static void main(String _args[]) throws Exception { final ReentrantLock lock = new ReentrantLock(); Runnable r = new Runnable(){ @Override public void run() { String name = Thread.currentThread().getName(); synchronized(lock){ System.out.println(name + ": acquire lock"); try { System.in.read(); System.out.println(name + ": is dead"); return; } catch (IOException _e) { _e.printStackTrace(); } } } }; Thread th1 = new Thread(r); Thread th2 = new Thread(r); th1.start(); th2.start(); th1.join(); th2.join(); } }