WEB开发网
开发学院软件开发Java 使用 Problem Diagnostics Lab Toolkit 增强故障排... 阅读

使用 Problem Diagnostics Lab Toolkit 增强故障排除技能

 2010-05-21 00:00:00 来源:WEB开发网   
核心提示: 清单 1. 按钮 DeadLock Jsp 执行的 Java 代码synchronized(lock1){//lock1isdefinedinthe"MethodsandStaticVariables"tabThread.sleep(5000);ThreadMonitor.r

清单 1. 按钮 DeadLock Jsp 执行的 Java 代码

synchronized (lock1) { // lock1 is defined in the "Methods and Static Variables" tab 
  Thread.sleep(5000); 
  ThreadMonitor.registerThreadStatus("blocked"); //It will be blocked here if the 
                          //thread can not get the lock2 
  synchronized (lock2) { 
  ThreadMonitor.registerThreadStatus("running"); //It will continue to run if the 
                          //thread can get the lock2 
  } 
 } 
synchronized (lock2) { // lock2 is defined in the "Methods and Static Variables" tab 
  Thread.sleep(5000); 
  ThreadMonitor.registerThreadStatus("blocked"); //It will be blocked here if the 
                          //thread can not get the lock1 
  synchronized (lock1) { 
  ThreadMonitor.registerThreadStatus("running"); //It will continue to run if the 
                          //thread can get the lock1 
  } 
 }

清单 1 中的代码执行下面的动作:

获得一个全局锁:lock1。

休眠 5 秒钟。

获得另一个全局锁:lock2。

释放全局锁:lock1。

释放全局锁:lock2。

获得一个全局锁:lock2。

上一页  1 2 3 4 5 6 7  下一页

Tags:使用 Problem Diagnostics

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接