码迷,mamicode.com
首页 > 编程语言 > 详细

Deadlock_synchromized-Java_se

时间:2016-04-13 18:54:43      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

class Test implements Runnable
{
private boolean flag;
Test(boolean flag)
{
this.flag = flag;
}
public void run()
{
if(flag)
{
synchronized(MyLock.locka)
{
System.out.println("if..locka");
synchronized(MyLock.lockb)
{
System.out.println("if..lockb");
}
}
}
else
{
synchronized(MyLock.lockb)
{
System.out.println("else..lockb");
synchronized(MyLock.locka)
{
System.out.println("else..locka");
}
}
}
}
}
class MyLock
{
public static final MyLock locka = new MyLock();
public static final MyLock lockb = new MyLock();
}
class DeadLockTest
{
public static void main(String[] args)
{
Test a = new Test(true);
Test b = new Test(false);
Thread t1 = new Thread(a);
Thread t2 = new Thread(b);
t1.start();
t2.start();

}
}

Deadlock_synchromized-Java_se

标签:

原文地址:http://www.cnblogs.com/tabchanj/p/5388085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!