线程同步

同步代码快,同步函数是以牺牲性能来换取程序安全的

string str  =new  string(""); 

while(true)

{

synchronized(str)

{

if(t>0)

{

try{

System.out.println(":"+t--);

}catch(Exception e)

{

}

}

}

}

posted on 2012-03-01 08:52  平安夜  阅读(101)  评论(0编辑  收藏  举报