package com.xwolf.java.thread.ch2;

/**
* Created by Administrator on 2016/1/4 0004.
*/
public class DeadLock {
private static String a ="A";
private static String b ="B"; public static void main(String[] args) {
new DeadLock().deadLock();
} private void deadLock(){
Thread thread1 = new Thread(new Runnable() { public void run() { synchronized (a) {
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} synchronized (b) {
System.out.println("Thread-0001");
}
} }
}); Thread thread2 = new Thread(new Runnable() { public void run() { synchronized (b) {
synchronized (a) {
System.out.println("Thread-0002");
}
} }
}); thread1.start();
thread2.start();
}
}

\D:\Program Files\Java\jdk1.7.0_79\bin>jps
11212 Launcher
7332 Jps
2744 RemoteMavenServer
10108 NailgunRunner
7760 AppMain
7152

D:\Program Files\Java\jdk1.7.0_79\bin>jstack -l 7760
2016-01-04 16:36:17
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode):

"DestroyJavaVM" prio=6 tid=0x0000000002745000 nid=0x2aa8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Thread-1" prio=6 tid=0x000000000ef63800 nid=0x13ec waiting for monitor entry [0x000000000fa1f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.xwolf.java.thread.ch2.DeadLock$2.run(DeadLock.java:44)
- waiting to lock <0x00000007c0b57ee8> (a java.lang.String)
- locked <0x00000007c0b57f18> (a java.lang.String)
at java.lang.Thread.run(Thread.java:745)

Locked ownable synchronizers:
- None

"Thread-0" prio=6 tid=0x000000000ef62800 nid=0x1c58 waiting for monitor entry [0x000000000f91f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.xwolf.java.thread.ch2.DeadLock$1.run(DeadLock.java:28)
- waiting to lock <0x00000007c0b57f18> (a java.lang.String)
- locked <0x00000007c0b57ee8> (a java.lang.String)
at java.lang.Thread.run(Thread.java:745)

Locked ownable synchronizers:
- None

"Monitor Ctrl-Break" daemon prio=6 tid=0x000000000ef72000 nid=0x18d4 runnable [0x000000000f81e000]
java.lang.Thread.State: RUNNABLE
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
- locked <0x00000007c0d3a1c8> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:530)
at java.net.ServerSocket.accept(ServerSocket.java:498)
at com.intellij.rt.execution.application.AppMain$1.run(AppMain.java:90)
at java.lang.Thread.run(Thread.java:745)

Locked ownable synchronizers:
- None

"Service Thread" daemon prio=6 tid=0x000000000d0e5800 nid=0x12d8 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"C2 CompilerThread1" daemon prio=10 tid=0x000000000d0d6000 nid=0x2314 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"C2 CompilerThread0" daemon prio=10 tid=0x000000000d0d4800 nid=0x728 waiting on
condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Attach Listener" daemon prio=10 tid=0x000000000d0d4000 nid=0x1b0 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Signal Dispatcher" daemon prio=10 tid=0x000000000d0d1000 nid=0x204c runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers:
- None

"Finalizer" daemon prio=8 tid=0x000000000282c800 nid=0x246c in Object.wait() [0x000000000e42f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007c0684858> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x00000007c0684858> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

Locked ownable synchronizers:
- None

"Reference Handler" daemon prio=10 tid=0x0000000002824800 nid=0x70 in Object.wait() [0x000000000e32f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007c0684470> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
- locked <0x00000007c0684470> (a java.lang.ref.Reference$Lock)

Locked ownable synchronizers:
- None

"VM Thread" prio=10 tid=0x000000000d093000 nid=0xe4c runnable

"GC task thread#0 (ParallelGC)" prio=6 tid=0x000000000275b800 nid=0x120 runnable

"GC task thread#1 (ParallelGC)" prio=6 tid=0x000000000275d800 nid=0x510 runnable

"GC task thread#2 (ParallelGC)" prio=6 tid=0x000000000275f000 nid=0x2564 runnable

"GC task thread#3 (ParallelGC)" prio=6 tid=0x0000000002761800 nid=0x244c runnable

"VM Periodic Task Thread" prio=10 tid=0x000000000d11a000 nid=0x14e8 waiting on condition

JNI global references: 153

Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x000000000282afa8 (object 0x00000007c0b57ee8, a java.lang.String),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x000000000282c238 (object 0x00000007c0b57f18, a java.lang.String),
which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
at com.xwolf.java.thread.ch2.DeadLock$2.run(DeadLock.java:44)
- waiting to lock <0x00000007c0b57ee8> (a java.lang.String)
- locked <0x00000007c0b57f18> (a java.lang.String)
at java.lang.Thread.run(Thread.java:745)
"Thread-0":
at com.xwolf.java.thread.ch2.DeadLock$1.run(DeadLock.java:28)
- waiting to lock <0x00000007c0b57f18> (a java.lang.String)
- locked <0x00000007c0b57ee8> (a java.lang.String)
at java.lang.Thread.run(Thread.java:745)

Found 1 deadlock.

可以看到程序中的死锁问题,已经线程的一系列信息。

[java] jstack 查看死锁问题的更多相关文章

  1. Java如何查看死锁

    Java中当我们的开发涉及到多线程的时候,这个时候就很容易遇到死锁问题,刚开始遇到死锁问题的时候,我们很容易觉得莫名其妙,而且定位问题也很困难. 因为涉及到java多线程的时候,有的问题会特别复杂,而 ...

  2. Java如何查看死锁?

    转载自 https://blog.csdn.net/u014039577/article/details/52351626 Java中当我们的开发涉及到多线程的时候,这个时候就很容易遇到死锁问题,刚开 ...

  3. jstack(查看线程)、jmap(查看内存)和jstat(性能分析)

    公司内部同事分享的一篇文章 周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令.供大家参考 1.Jstack 1.1 ...

  4. jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令

    jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令   公司内部同事分享的一篇文章 周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jma ...

  5. Java多线程:死锁

    周末看到一个用jstack查看死锁的例子.昨天晚上总结了一下jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令.供大家参考  1.Jstack 1.1 jstack能得到运行j ...

  6. 命令:jstack(查看线程)、jmap(查看内存)和jstat(性能分析)命令

    命令:jstack(查看线程).jmap(查看内存)和jstat(性能分析)命令 这些命令 必须 在 linux jdk bin 路径 下执行 eq: ./jstack 10303 即可  如果想把 ...

  7. Java 查看死锁的方法

    那我们怎么确定一定是死锁呢?有两种方法. 1>使用JDK给我们的的工具JConsole,可以通过打开cmd然后输入jconsole打开. 1)连接到需要查看的进程.

  8. java -jstack

    一.介绍 jstack是java虚拟机自带的一种堆栈跟踪工具.jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项&qu ...

  9. java 实现一个死锁

    /** * 死锁:两个或多个线程在执行过程中,相互争夺资源而造成的一种互相等待的现象 * 实现一个死锁 * <p> * <p> * 查看死锁 * 1. 在当前类的文件夹下,打开 ...

随机推荐

  1. Python 里 and、or 的计算规则

    引子: >>> print '' or 5 or 05>>> print 5 and 44>>> print '' or 5 or 0 and 4 ...

  2. Java日志 (zhuan)

    http://www.cnblogs.com/bird-li/p/4696662.html ************************************************* 日志对于 ...

  3. kafka之partition分区及副本replica升级

    修改kafka的partition分区 bin/kafka-topics.sh --zookeeper datacollect-2:2181 --alter --partitions 3 --topi ...

  4. Gson json解析工具

    json 解析工具 ,谷歌出品 对象转换字符串 HashMap<String,String> hashMap = new HashMap<String, String>();  ...

  5. 在N个元素的数组中获取K个元素的所有组合问题

    可以写循环,也可以用模块. 百度许久找到一个博客 http://blog.sina.com.cn/s/blog_4a0824490101f1kc.html 详细介绍了Algorithm::Combin ...

  6. Oracle PL/SQL 编程基础 实例

    create table mytest(name varchar(20),password varchar(30)); create or replace procedure sp_pro2 is  ...

  7. C语言高速入门系列(八)

    C语言高速入门系列(八) C语言位运算与文件 本章引言: 在不知不觉中我们的C高速入门系列已经慢慢地接近尾声了,而在这一节中,我们会对 C语言中的位运算和文件进行解析,相信这两章对于一些人来说是陌生的 ...

  8. 【Visual Studio】VS常用调试技巧——笔记

    CSDN的文档: https://msdn.microsoft.com/en-us/library/aa295838(v=vs.60).aspx 情景一:[监视]变量时,当运行离开当前函数后,怎么看到 ...

  9. 碰到故障大全---cd

    office已安装32位,无法安装64位?解决方案:开始→运行→输入regedit,打开注册表编辑器,找到HKEY_CLASSES_ROOT\\Installer\\Products\ \000021 ...

  10. 飞飞影视cms标签

    解析范围: 全站所有模板均可调用 模板名称: 所有模板 调用函数: ff_mysql_vod(参数1:值1;参数2:值2;参数3,值3....;参数n,值n),支持的参数列表如下 * 以下变量名如$v ...