Posted on 2008-12-06 12:14
鱼跃于渊 阅读(124)
评论(0) 编辑 收藏 所属分类:
j2se
1
2 public class TT implements Runnable{
3 int b = 10 ;
4
5 public synchronized void m1() throws Exception{
6 b = 1000 ;
7 Thread.sleep(5000);
8 System.out.println("m1 : b = " + b) ;
9 }
10
11 public void m2(){
12 System.out.println("m2 : b = " + b) ;
13 }
14
15 public void run(){
16 try{
17 m1() ;
18 }catch(Exception ex){
19 ex.printStackTrace() ;
20 }
21 }
22
23 public static void main(String[] args) throws Exception{
24 TT tt = new TT() ;
25 Thread t = new Thread(tt) ;
26 t.start() ;
27 Thread.sleep(2000) ;
28 tt.m2() ;
29 }
30 }