comparison 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
comparison
equal deleted inserted replaced
24:68021f7091e1 25:c1e7ec6b3d44
1 package treecms.test;
2
3 import java.io.IOException;
4 import java.util.concurrent.locks.ReentrantLock;
5
6 public class ReentrantLockTest1
7 {
8 public static void main(String _args[]) throws Exception
9 {
10 final ReentrantLock lock = new ReentrantLock();
11
12 Runnable r = new Runnable(){
13 @Override
14 public void run()
15 {
16 String name = Thread.currentThread().getName();
17 synchronized(lock){
18 System.out.println(name + ": acquire lock");
19 try {
20 System.in.read();
21 System.out.println(name + ": is dead");
22 return;
23 } catch (IOException _e) {
24 _e.printStackTrace();
25 }
26 }
27 }
28 };
29
30 Thread th1 = new Thread(r);
31 Thread th2 = new Thread(r);
32
33 th1.start();
34 th2.start();
35
36 th1.join();
37 th2.join();
38 }
39 }