java线程转储
java的线程转储可以被定义为JVM中在某一个给定的时刻运行的所有线程的快照。一个线程转储可能包含一个单独的线程或者多个线程。在多线程环境中,比如J2EE应用服务器,将会有许多线程和线程组。每一个线程都有它自己的调用堆栈,在一个给定时刻,表现为一个独立功能。线程转储将会提供JVM中所有线程的堆栈信息,对于特定的线程也会给出更多信息。
java虚拟机进程和java线程
java虚拟机,或者称为JVM,是一个操作系统级别的进程。java线程是JVM进程的子进程或者轻量级进程(Solar中的叫法)。
生成java线程转储
线程转储可以通过向JVM进程发送一个SIGQUIT信号来生成。有两种不同方式来向进程发送这个信号:
在Unix中,使用“kill -3<pid>”命令,pid表示JVM进程的ID。
在Windows中,在JVM运行时按下CTRL+BREAK键 ,或者使用 jstack 来生成。
[fox]:jstack jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息。
Java线程状态
每一个java线程总是处于其生命周期的四个状态之一。
Runnable-线程正在运行,或者准备好获取CPU时间后运行。JRockit线程转储中把这种状态当做Active。
Waiting on Monitor-线程休眠,或者在等待一个对象,或者等待被其他线程唤醒。在线程对象中调用sleep()方法,或者在一个对象中调用wait()方法时就会有这种情况发生。
举个例子,在WebLogc服务器中,空闲的执行线程处于这种状态,他们会一直等待直到一个Socket reader线程有新的任务才唤醒他们。堆栈信息就会如下所示:
"ExecuteThread: '2' for queue: 'weblogic.admin.RMI'" daemon prio=5 tid=0x1752F040 nid=0x180c in Object.wait() [1887f000..1887fd8c]
at java.lang.Object.wait(Native Method) waiting on <04134D98> (a weblogic.kernel.ExecuteThread)
at java.lang.Object.wait(Object.java:426)
at weblogic.kernel.ExecuteThread.waitForRequest(ExecuteThread.java:126)
locked <04134D98> (a weblogic.kernel.ExecuteThread)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:145)
在某些别的版本的JVM中称这种状态是CW,Object.wait()(像上面那样)。JRockit称之为WAITING。
Waiting for Monitor Entry——线程在等待获取一个对象的锁(其他线程可能持有这个同步锁)。这种情况发生在当两个或者更多线程尝试执行一段同步代码时。注意“锁”总是针对于一个对象而不是针对一个单独的方法。
这种情况的线程的简单堆栈信息如下:
如:
/**
*
*
* @author mjorcen
* @email mjorcen@gmail.com
* @dateTime Jan 27, 2015 10:51:24 AM
* @version 1
*/
public class DeadThread {
private static Object obj1 = new Object();
private static Object obj2 = new Object(); public static void main(String[] args) {
new Thread(new Runnable() { public void run() {
synchronized (obj1) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (obj2) {
System.out.println(1);
}
}
}
}, "t-0").start();
new Thread(new Runnable() { public void run() {
synchronized (obj2) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (obj1) {
System.out.println(2);
}
}
}
}, "t-1").start(); }
}
在 jstack 中.
结果:
2015-01-27 10:54:12
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.55-b03 mixed mode): "RMI TCP Connection(2)-192.168.1.7" daemon prio=6 tid=0x000000000c016000 nid=0x1030 runnable [0x000000000d73e000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
- locked <0x00000007d73f8200> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:538)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- <0x00000007d6f99578> (a java.util.concurrent.ThreadPoolExecutor$Worker) "JMX server connection timeout 16" daemon prio=6 tid=0x000000000bedc800 nid=0x1bc8 in Object.wait() [0x000000000ce2f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d712d470> (a [I)
at com.sun.jmx.remote.internal.ServerCommunicatorAdmin$Timeout.run(ServerCommunicatorAdmin.java:168)
- locked <0x00000007d712d470> (a [I)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- None "RMI Scheduler(0)" daemon prio=6 tid=0x000000000bedc000 nid=0xa08 waiting on condition [0x000000000cc2e000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007d6ef7798> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- None "RMI TCP Connection(1)-192.168.1.7" daemon prio=6 tid=0x000000000bf09800 nid=0x16e0 runnable [0x000000000cb0f000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
- locked <0x00000007d70d2dd0> (a java.io.BufferedInputStream)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:538)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- <0x00000007d6f971f0> (a java.util.concurrent.ThreadPoolExecutor$Worker) "RMI TCP Accept-0" daemon prio=6 tid=0x000000000bf81800 nid=0x15c runnable [0x000000000c93f000]
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:198)
- locked <0x00000007d6f07c40> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:530)
at java.net.ServerSocket.accept(ServerSocket.java:498)
at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:52)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:388)
at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:360)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- None "DestroyJavaVM" prio=6 tid=0x000000000027d800 nid=0x1b0c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "Thread-1" prio=6 tid=0x000000000be08800 nid=0x1864 waiting for monitor entry [0x000000000c34f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at mjorcen.nio.test.DeadThread$2.run(DeadThread.java:48)
- waiting to lock <0x00000007d6b1d530> (a java.lang.Object)
- locked <0x00000007d6b1d540> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- None "Thread-0" prio=6 tid=0x000000000a74d800 nid=0x196c waiting for monitor entry [0x000000000bdff000]
java.lang.Thread.State: BLOCKED (on object monitor)
at mjorcen.nio.test.DeadThread$1.run(DeadThread.java:32)
- waiting to lock <0x00000007d6b1d540> (a java.lang.Object)
- locked <0x00000007d6b1d530> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:745) Locked ownable synchronizers:
- None "Service Thread" daemon prio=6 tid=0x000000000a741000 nid=0x1aec runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "C2 CompilerThread1" daemon prio=10 tid=0x000000000a73c800 nid=0x1bd8 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "C2 CompilerThread0" daemon prio=10 tid=0x000000000a72b800 nid=0xba0 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "Attach Listener" daemon prio=10 tid=0x000000000a72a800 nid=0x12d0 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "Signal Dispatcher" daemon prio=10 tid=0x000000000a729800 nid=0x5d4 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None "Finalizer" daemon prio=8 tid=0x00000000024cf800 nid=0x192c in Object.wait() [0x000000000b6ef000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d6a85568> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x00000007d6a85568> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189) Locked ownable synchronizers:
- None "Reference Handler" daemon prio=10 tid=0x00000000024cb800 nid=0xae4 in Object.wait() [0x000000000b57f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d6a850f0> (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 <0x00000007d6a850f0> (a java.lang.ref.Reference$Lock) Locked ownable synchronizers:
- None "VM Thread" prio=10 tid=0x000000000a6b2000 nid=0x1194 runnable "GC task thread#0 (ParallelGC)" prio=6 tid=0x0000000002404800 nid=0x1a74 runnable "GC task thread#1 (ParallelGC)" prio=6 tid=0x0000000002406000 nid=0x1a7c runnable "VM Periodic Task Thread" prio=10 tid=0x000000000a74a000 nid=0x13fc waiting on condition JNI global references: 150 Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x000000000a6ba6d8 (object 0x00000007d6b1d530, a java.lang.Object),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x000000000a6b9238 (object 0x00000007d6b1d540, a java.lang.Object),
which is held by "Thread-1" Java stack information for the threads listed above:
===================================================
"Thread-1":
at mjorcen.nio.test.DeadThread$2.run(DeadThread.java:48)
- waiting to lock <0x00000007d6b1d530> (a java.lang.Object)
- locked <0x00000007d6b1d540> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:745)
"Thread-0":
at mjorcen.nio.test.DeadThread$1.run(DeadThread.java:32)
- waiting to lock <0x00000007d6b1d540> (a java.lang.Object)
- locked <0x00000007d6b1d530> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:745) Found 1 deadlock.
Java 死锁诊断 -- 线程转储的更多相关文章
-
Java并发之线程转储
一.java线程转储 java的线程转储可以被定义为JVM中在某一个给定的时刻运行的所有线程的快照.一个线程转储可能包含一个单独的线程或者多个线程.在多线程环境中,比如J2EE应用服务器,将会有许多线 ...
-
Java 线程转储 [转]
http://www.oschina.net/translate/java-thread-dump java线程转储 java的线程转储可以被定义为JVM中在某一个给定的时刻运行的所有线程的快照.一个 ...
-
Java 线程转储
软件维护是一个枯燥而又有挑战性的工作.只要软件功能符合预期,那么这个工作就是好的.设想一个这样的情景,你的电话半夜也一直在响(这不是一个令人愉快的感受,是吧?)任何软件系统,无论它当初是被设计的多好, ...
-
获取Java线程转储的常用方法
1. 线程转储简介 线程转储(Thread Dump)就是JVM中所有线程状态信息的一次快照. 线程转储一般使用文本格式, 可以将其保存到文本文件中, 然后人工查看和分析, 或者使用工具/API自动分 ...
-
JAVA之旅(十四)——静态同步函数的锁是class对象,多线程的单例设计模式,死锁,线程中的通讯以及通讯所带来的安全隐患,等待唤醒机制
JAVA之旅(十四)--静态同步函数的锁是class对象,多线程的单例设计模式,死锁,线程中的通讯以及通讯所带来的安全隐患,等待唤醒机制 JAVA之旅,一路有你,加油! 一.静态同步函数的锁是clas ...
-
【Java】线程转储分析 ThreadDump
[[TOC]] 通过分析 ThreadDump 来查询Java程序运行情况 获取线程转储文件 有多种方式可以获取转储文件,可参考链接HOW TO TAKE THREAD DUMPS? – 8 OPTI ...
-
java多线程之 ---- 线程死锁
java多线程之线程死锁 产生死锁的主要原因: 由于系统资源不足. 进程执行推进的顺序不合适. 资源分配不当等. 假设系统资源充足.进程的资源请求都可以得到满足,死锁出现的可能性就非常低.否则就会因争 ...
-
Java基础_死锁、线程组、定时器Timer
一.死锁问题: 死锁是这样一种情形:多个线程同时被阻塞,它们中的一个或者全部都在等待某个资源被释放.由于线程被无限期地阻塞,因此程序不可能正常终止. 比如,线程一需要第一把所,此时锁处于空闲状态,给了 ...
-
Java虚拟机性能管理神器 - VisualVM(9) 排查JAVA应用程序线程死锁【转】
Java虚拟机性能管理神器 - VisualVM(9) 排查JAVA应用程序线程死锁[转] 标签: javajvm监控工具性能优化 2015-03-11 19:59 1948人阅读 评论(0) 收藏 ...
随机推荐
-
Oracle编程脚本记录
--命令窗口查询 exec 存储名.包名.视图; select 函数名 from dual; create or replace procedure PR_test is begin --存储过程的代 ...
-
01-04-03【Nhibernate (版本3.3.1.4000) 出入江湖】Criteria API关联查询
Criteria API关联查询 如果说HQL查询还有需要了解点SQL语法知识,并不是完全彻底面向对象查询, 那么Criterial API就是完全面向对象的查询方式. public IList< ...
-
Bzoj 3809: Gty的二逼妹子序列 莫队,分块
3809: Gty的二逼妹子序列 Time Limit: 35 Sec Memory Limit: 28 MBSubmit: 868 Solved: 234[Submit][Status][Dis ...
-
ES6之Promise学习与实践
1.前言 在平时的业务开发中,前端通常需要请求后台获取数据,或者NodeJs读取文件等等一系列的异步操作,我们通常需要利用异步操作的结果或者对异步操作的结果进行处理.通常我们的解决方案是:在异步操作成 ...
-
.NET Core 的缓存篇之MemoryCache
前言 对于缓存我们都已经很熟悉了,缓存分为很多种,浏览器缓存.试图缓存.服务器缓存.数据库缓存等等一些,那今天我们先介绍一下视图缓存和MemoryCache内存缓存的概念和用法: 视图缓存 在老的版本 ...
-
Fum uc M-R ko P&#39;s R
Milr-Rabin Dodod Avlo se \(n-1\) e \(u\cdot 2^t\). hen goch'n Toizz lme \([1,n-1]\) e \(l\). cak fe ...
-
spring拦截器中使用spring的自动注入
需要在spring的拦截器中使用自定义的服务,这要就设计到将服务注入到拦截器中.网上看的情况有两种: 1. @Configuration public class OptPermissionHandl ...
-
jquery $.ajax $.get $.post的区别?
$.ajax 是 jQuery 底层 AJAX 实现,$.ajax是一种通用的底层封装,$.ajax()请求数据之后,则需要使用回调函数,有beforeSend.error.dataFilter.su ...
-
数据结构(C语言版)-第5章 树和二叉树
5.1 树和二叉树的定义 树(Tree)是n(n≥0)个结点的有限集,它或为空树(n = 0):或为非空树,对于非空树T:(1)有且仅有一个称之为根的结点:(2)除根结点以外的其余结点可分为m(m& ...
-
Java 8 – How to sort a Map
Java 8 – How to sort a Map 1. Quick ExplanationMap result = map.entrySet().stream() .sorted(Map.Entr ...