首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

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

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

使用 PDTK为了带领您遍历使用 PDTK 的整个过程,让我们来了解一个死锁场景。
从左侧的 Problems 窗格选择 ThreadHang,然后从 Scenarios 列表选择 Dead                Lock。这将同时显示 scenario guide(图 3)和 action 窗格(图 4)。
图 3. Scenario guide该向导可以协助完成这个场景。如图 3 所示,这些步骤为:
  • Instruction:概述将要在场景中重现的问题。
  • Reproduction:描述场景过程和技巧。
  • Investigation:指导用户处理问题诊断。
  • Summary:总结问题。
可以添加或移除步骤,甚至改变它们的内容,这是通过 wizard 窗格的下拉菜单完成的。下拉菜单的选项包括:
  • Remove step
  • New step
  • Edit step
图 4. Action 窗格查看代码如图 4 所示,为死锁场景生成的 action 窗格中有两个动作按钮:DeadLock Jsp 和 Correct Jsp。和 wizard 窗格一样,action 窗格的下拉菜单包括以下按钮:
  • Remove action
  • New action
  • Edit action
要查看或编辑死锁 Java 代码,右键单击 DeadLock Jsp                按钮并选择 Edit Action 按钮。代码如清单 1 和图 5 所示。
清单 1. 按钮 DeadLock Jsp 执行的 Java 代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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。
  • 休眠 5 秒钟。
  • 获得一个全局锁:lock1。
  • 释放全局锁:lock2。
  • 释放全局锁:lock1。
这个代码片段可以在单线程环境中安全运行;然而,它会在多线程环境下引起死锁。当两个不同的线程在步骤 2 和步骤 6 之前独立运行时,其中一个线程已经占用了 lock1 并等待 lock2,反之亦然。因此,如果您模拟多个同时运行此代码的客户机,那么就会重现死锁场景。
图 5. 单击                    Edit Action 按钮后出现的代码编辑器压力模拟PDTK 提供了一个内置的压力引擎,可以轻松地模拟并发访问场景。图 6 展示了如何设置压力引擎:展开 Advanced Settings 窗格并配置 Client numberInvoke timesThink time(请求之间的时间间隔)。在本文中,将客户机的数量设置为 2。在配置好高级设置后,展开 Action Buttons 窗格并单击 DeadLock Jsp 按钮。压力引擎将模拟两个向 Dead Lock JSP 发送同步请求的客户机。
图 6. 设置压力引擎
返回列表