JAVA 死锁
2015-11-22 13:16
393 查看
class Locker
{
static Object lockerA=new Object();
static Object lockerB=new Object();
}
class CRun implements Runnable
{
boolean flag=false;
public CRun(boolean flag)
{
this.flag=flag;
}
public void run()
{
if(flag)
{
synchronized(Locker.lockerA)
{
System.out.println("True get lockerA");
synchronized(Locker.lockerB)
{
System.out.println("True get lockerB");
}
}
}
else
{
synchronized(Locker.lockerB)
{
System.out.println("False get lockerB");
synchronized(Locker.lockerA)
{
System.out.println("False get lockerA");
}
}
}
}
}
class DeadLockerTest
{
public static void main(String[] args)
{
Thread thread1=new Thread(new CRun(false));
Thread thread2=new Thread(new CRun(true));
thread1.start();
thread2.start();
}
}
{
static Object lockerA=new Object();
static Object lockerB=new Object();
}
class CRun implements Runnable
{
boolean flag=false;
public CRun(boolean flag)
{
this.flag=flag;
}
public void run()
{
if(flag)
{
synchronized(Locker.lockerA)
{
System.out.println("True get lockerA");
synchronized(Locker.lockerB)
{
System.out.println("True get lockerB");
}
}
}
else
{
synchronized(Locker.lockerB)
{
System.out.println("False get lockerB");
synchronized(Locker.lockerA)
{
System.out.println("False get lockerA");
}
}
}
}
}
class DeadLockerTest
{
public static void main(String[] args)
{
Thread thread1=new Thread(new CRun(false));
Thread thread2=new Thread(new CRun(true));
thread1.start();
thread2.start();
}
}
相关文章推荐
- spring和hibernate框架的整合和事务管理
- 深入理解Java的接口和抽象类
- springMVC web.xml配置文件
- java 向上转型和向下转型
- 项目中页面未找到统一跳转到一个notfound页面
- 传智播客javase总结 4
- eclipse配置java之opencv
- getting started with java learn
- 冒泡排序JAVA_122-123
- 我的第四个程序 java实现加减乘除
- java nio socket通信简单入门示例
- jaxws webservice spring 注入 解决NullPointerException
- java设计模式-装饰者模式
- java制作简单日历
- 《疯狂Java讲义》第1章——Java语言概述与开发环境
- 我的第三个java程序 两数相加
- sublime添加eclipse快捷键
- java后台发起请求方式
- rk3288_android5.1__android4.4 jdk1.6和jdk1.7共存问题 ubuntu java7 The required version is: "1.7.x"
- springMvc实现