JAVA 线程 同步

来源:互联网 发布:淘宝商城首页 编辑:程序博客网 时间:2024/06/17 00:22

class Test6{

public void test(String str){
Object o = new Object();
synchronized(o){
System.out.println(str);
}
}


public static void main(String str[]){


class T extends Thread{


private Test6 t6;
public T(Test6 t6){
this.t6 = t6;
};
public void run(){
try{
Thread.sleep(4000);
}catch(Exception e){};
this.t6.test("T");
}


}


class TT extends Thread{


private Test6 t6;
public TT(Test6 t6){
this.t6 = t6;
};
public void run(){
this.t6.test("TT");
}


}




Test6 t6 = new Test6();


T t = new T(t6);
TT tt = new TT(t6);

t.start();
tt.start();



}

}


这篇纯属扯淡,自己鉴定完毕,顺便BS下自己

原创粉丝点击