JVM优化篇章一

1.jvm运行参数

三种参数类型

1.1 标准参数

  1. -help
  2. -version

jvm的标准参数,一般都是很稳定的,在未来的JVM版本中不会改变,可以使用java -help检索出所有的标准参数。

  1. C:\Users\CYJ>java -help
  2. 用法: java [-options] class [args...] (执行类)
  3. java [-options] -jar jarfile [args...] (执行 jar 文件)
  4. 其中选项包括:
  5. -d32 使用 32 位数据模型 (如果可用)
  6. -d64 使用 64 位数据模型 (如果可用)
  7. -server 选择 "server" VM 默认 VM server.
  8. -cp <目录和 zip/jar 文件的类搜索路径>
  9. -classpath <目录和 zip/jar 文件的类搜索路径>
  10. ; 分隔的目录, JAR 档案
  11. ZIP 档案列表, 用于搜索类文件。
  12. -D<名称>=<值> 设置系统属性
  13. -verbose:[class|gc|jni] 启用详细输出
  14. -version 输出产品版本并退出
  15. -version:<值> 警告: 此功能已过时, 将在未来发行版中删除。需要指定的版本才能运行
  16. -showversion 输出产品版本并继续
  17. -jre-restrict-search | -no-jre-restrict-search
  18. 警告: 此功能已过时, 将在未来发行版中删除。在版本搜索中包括/排除用户专用 JRE
  19. -? -help 输出此帮助消息
  20. -X 输出非标准选项的帮助
  21. -ea[:<packagename>...|:<classname>]
  22. -enableassertions[:<packagename>...|:<classname>]
  23. 按指定的粒度启用断言
  24. -da[:<packagename>...|:<classname>]
  25. -disableassertions[:<packagename>...|:<classname>]
  26. 禁用具有指定粒度的断言
  27. -esa | -enablesystemassertions 启用系统断言
  28. -dsa | -disablesystemassertions 禁用系统断言
  29. -agentlib:<libname>[=<选项>]
  30. 加载本机代理库 <libname>, 例如 -agentlib:hprof
  31. 另请参阅 -agentlib:jdwp=help -agentlib:hprof=help
  32. -agentpath:<pathname>[=<选项>] 按完整路径名加载本机代理库
  33. -javaagent:<jarpath>[=<选项>] 加载 Java 编程语言代理, 请参阅 java.lang.instrument
  34. -splash:<imagepath> 使用指定的图像显示启动屏幕
  35. 有关详细信息, 请参阅 http://www.oracle.com/technetwork/java/javase/documentation/index.html。

通过-D设置系统属性参数

  1. public class TestJVM {
  2. public static void main(String[] args) {
  3. String str = System.getProperty("str");
  4. if (str == null) {
  5. System.out.println("word");
  6. } else {
  7. System.out.println(str);
  8. }
  9. }
  10. }

进行编译、测试:

  1. javac TestJVM.java # 编译
  2. java TestJVM #测试
  3. word #输出结果
  4. java Dstr=123 TestJVM #-D设置系统属性参数
  5. 123 #输出结果
  1. C:\Users\CYJ>java -version
  2. java version "1.8.0_151"
  3. Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
  4. Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

-server与-client参数

  1. 可以通过-server或-client设置jvm的运行参数。
  2. 它们的区别是:
  3. Server VM的初始堆空间会大一些,默认使用的是并行垃圾回收器,启动慢运行快。
  4. Client VM相对来讲会保守一些,初始堆空间会小一些,使用串行的垃圾回收器,它的目标是为了让JVM的启动速度更快,但运行速度会比Serverm模式慢些。JVM在启动的时候会根据硬件和操作系统自动选择使用Server还是Client类型的JVM
  5. 32位操作系统
  6. 如果是Windows系统,不论硬件配置如何,都默认使用Client类型的JVM
  7. 如果是其他操作系统上,机器配置有2GB以上的内存同时有2个以上CPU的话默认使用server模式,否则使用client模式。
  8. 64位操作系统
  9. 只有server类型,不支持client类型。

1.2 -X参数 (非标准参数)

  1. -Xint
  2. -Xcomp
  1. C:\Users\CYJ>java -X
  2. -Xmixed 混合模式执行 (默认)
  3. -Xint 仅解释模式执行
  4. -Xbootclasspath: <用 ; 分隔的目录和 zip/jar 文件> 设置搜索路径以引导类和资源
  5. -Xbootclasspath/a: <用 ; 分隔的目录和 zip/jar 文件> 附加在引导类路径末尾
  6. -Xbootclasspath/p: <用 ; 分隔的目录和 zip/jar 文件> 置于引导类路径之前
  7. -Xdiag 显示附加诊断消息
  8. -Xnoclassgc 禁用类垃圾收集
  9. -Xincgc 启用增量垃圾收集
  10. -Xloggc:<file> GC 状态记录在文件中 (带时间戳)
  11. -Xbatch 禁用后台编译
  12. -Xms<size> 设置初始 Java 堆大小
  13. -Xmx<size> 设置最大 Java 堆大小
  14. -Xss<size> 设置 Java 线程堆栈大小
  15. -Xprof 输出 cpu 配置文件数据
  16. -Xfuture 启用最严格的检查, 预期将来的默认值
  17. -Xrs 减少 Java/VM 对操作系统信号的使用 (请参阅文档)
  18. -Xcheck:jni JNI 函数执行其他检查
  19. -Xshare:off 不尝试使用共享类数据
  20. -Xshare:auto 在可能的情况下使用共享类数据 (默认)
  21. -Xshare:on 要求使用共享类数据, 否则将失败。
  22. -XshowSettings 显示所有设置并继续
  23. -XshowSettings:all
  24. 显示所有设置并继续
  25. -XshowSettings:vm 显示所有与 vm 相关的设置并继续
  26. -XshowSettings:properties 显示所有属性设置并继续
  27. -XshowSettings:locale 显示所有与区域设置相关的设置并继续
  28. -X 选项是非标准选项, 如有更改, 恕不另行通知。

-Xint、-Xcomp、-Xmixed

  1. -Xint标记会强制JVM执行所有的字节码,当然这会降低运行速度,通常低10倍或更多。
  2. -Xcomp参数与它(-Xint)正好相反,JVM在第一次使用时会把所有的字节码编译成本地代码,从而带来最大程度的优化
  3. 然而,很多应用在使用-Xcomp也会有一些性能损失,当然这比使用-Xint损失的少,原因是-xcomp没有让JVM启用JIT 译器的全部功能。JIT编译器可以对是否需要编译做判断,如果所有代码都进行编译的话,对于一些只执行一次的代码就 没有意义了。
  4. -Xmixed是混合模式,将解释模式与编译模式进行混合使用,由jvm自己决定,这是jvm默认的模式,也是推荐使用的模式。

1.3 -XX参数(使用率较高)

  1. -XX:newSize
  2. -XX:+UseSerialGC
  1. -XX参数也是非标准参数,主要用于jvm的调优和debug操作。
  2. -XX参数的使用有2种方式,一种是boolean类型,一种是非boolean类型:
  3. boolean类型
  4. 格式:-XX:[+-]
  5. 如:-XX:+DisableExplicitGC 表示禁用手动调用gc操作,也就是说调用System.gc()无效
  6. boolean类型
  7. 格式:-XX:
  8. 如:-XX:NewRatio=1 表示新生代和老年代的比值

-Xms与-Xmx参数

  1. -Xms与-Xmx分别是设置jvm的堆内存的初始大小和最大大小。
  2. -Xmx2048m:等价于-XX:MaxHeapSize,设置JVM最大堆内存为2048M
  3. -Xms512m:等价于-XX:InitialHeapSize,设置JVM初始堆内存为512M
  4. 适当的调整jvm的内存大小,可以充分利用服务器资源,让程序跑的更快。

查看jvm的运行参数

  1. 查看jvm的运行参数,这个需求可能会存在2种情况:
  2. 第一,运行java命令时打印出运行参数;需要添加-XX:+PrintFlagsFinal参数即可。
  3. 第二,查看正在运行的java进程的参数;jinfo命令查看。
  4. 查看所有的参数,用法:jinfo flags <进程id>
  5. 通过jps 或者 jps l 查看java进程
  6. 查看某一参数的值,用法:jinfo flag <参数名> <进程id>

2.jvm的内存模型

2.1 jdk1.7的堆内存模型

2020-08-10_205519.png

  1. Young 年轻区(代)
  2. Young区被划分为三部分,Eden区和两个大小严格相同的Survivor区,其中,Survivor区间中,某一时刻只有其中一个是被使用的,另外一个留做垃圾收集时复制对象用,在Eden区间变满的时候, GC就会将存活的对象移到空闲的Survivor区间
  3. 中,根据JVM的策略,在经过几次垃圾收集后,任然存活于Survivor的对象将被移动到Tenured区间。
  4. Tenured 年老区
  5. Tenured区主要保存生命周期长的对象,一般是一些老的对象,当一些对象在Young复制转移一定的次数以后,对象就会被转移到Tenured区,一般如果系统中用了application级别的缓存,缓存中的对象往往会被转移到这一区间。
  6. Perm 永久区
  7. Perm代主要保存class,method,filed对象,这部份的空间一般不会溢出,除非一次性加载了很多的类,不过在涉及到热部署的应用服务器的时候,有时候会遇到java.lang.OutOfMemoryError : PermGen space 的错误,造成这个错误的很大原因
  8. 就有可能是每次都重新部署,但是重新部署后,类的class没有被卸载掉,这样就造成了大量的class对象保存在了perm中,这种情况下,一般重新启动应用服务器可以解决问题。
  9. Virtual区:
  10. 最大内存和初始内存的差值,就是Virtual区。

2.2 jdk1.8的堆内存模型

2020-08-10_205724.png

  1. 由上图可以看出,jdk1.8的内存模型是由2部分组成,年轻代 + 年老代。
  2. 年轻代:Eden + 2*Survivor
  3. 年老代:OldGen
  4. jdk1.8中变化最大的Perm区,用Metaspace(元数据空间)进行了替换。需要特别说明的是:Metaspace所占用的内存空间不是在虚拟机内部,而是在本地内存空间中,这也是与1.7的永久代最大的区别所在。

2.3 为什么要废弃1.7中的永久区?

官网给出了解释:http://openjdk.java.net/jeps/122

  1. This is part of the JRockit and Hotspot convergence effort. JRockit customers do not need to configure the permanent generation (since JRockit does not have a permanent generation) and are accustomed to not configuring the permanent generation.
  2. 移除永久代是为融合HotSpot JVM JRockit VM而做出的努力,因为JRockit没有永久代,不需要配置永久代。

现实使用中,由于永久代内存经常不够用或发生内存泄露,爆出异常java.lang.OutOfMemoryError: PermGen。基于此,将永久区废弃,而改用元空间,改为了使用本地内存空间。

2.4 通过jstat命令进行查看堆内存使用情况

  1. jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。命令的格式如下:
  2. jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]

查看class加载统计

  1. C:\Users\CYJ>jps
  2. 11728 Bootstrap
  3. 14060 Jps
  4. C:\Users\CYJ>jstat -class 11728
  5. Loaded Bytes Unloaded Bytes Time
  6. 3189 6200.7 0 0.0 1.83
  1. 说明:
  2. Loaded:加载class的数量
  3. Bytes:所占用空间大小
  4. Unloaded:未加载数量
  5. Bytes:未加载占用空间
  6. Time:时间

查看编译统计

  1. C:\Users\CYJ>jstat -compiler 11728
  2. Compiled Failed Invalid Time FailedType FailedMethod
  3. 1901 0 0 2.29 0
  1. 说明:
  2. Compiled:编译数量。
  3. Failed:失败数量
  4. Invalid:不可用数量
  5. Time:时间
  6. FailedType:失败类型
  7. FailedMethod:失败的方法

垃圾回收统计

  1. C:\Users\CYJ>jstat -gc 11728
  2. S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
  3. 10752.0 10752.0 0.0 10730.1 65024.0 30674.4 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  4. #也可以指定打印的间隔和次数,每1秒中打印一次,共打印5
  5. C:\Users\CYJ>jstat -gc 11728 1000 5
  6. S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
  7. 10752.0 10752.0 0.0 10730.1 65024.0 30999.6 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  8. 10752.0 10752.0 0.0 10730.1 65024.0 30999.6 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  9. 10752.0 10752.0 0.0 10730.1 65024.0 30999.6 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  10. 10752.0 10752.0 0.0 10730.1 65024.0 30999.6 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  11. 10752.0 10752.0 0.0 10730.1 65024.0 30999.6 173568.0 3967.0 17152.0 16607.2 2048.0 1891.7 1 0.011 0 0.000 0.011
  1. 说明:
  2. S0C:第一个Survivor区的大小(KB
  3. S1C:第二个Survivor区的大小(KB
  4. S0U:第一个Survivor区的使用大小(KB
  5. S1U:第二个Survivor区的使用大小(KB
  6. ECEden区的大小(KB
  7. EUEden区的使用大小(KB
  8. OCOld区大小(KB
  9. OUOld使用大小(KB
  10. MC:方法区大小(KB
  11. MU:方法区使用大小(KB
  12. CCSC:压缩类空间大小(KB
  13. CCSU:压缩类空间使用大小(KB
  14. YGC:年轻代垃圾回收次数
  15. YGCT:年轻代垃圾回收消耗时间
  16. FGC:老年代垃圾回收次数
  17. FGCT:老年代垃圾回收消耗时间
  18. GCT:垃圾回收消耗总时间

3.jmap的使用以及内存溢出分析

前面通过jstat可以对jvm堆的内存进行统计分析,而jmap可以获取到更加详细的内容,如:内存使用情况的汇总、对内存溢出的定位与分析。

3.1 查看内存使用情况

  1. C:\Users\CYJ>jmap -heap 11728
  2. Attaching to process ID 11728, please wait...
  3. Debugger attached successfully.
  4. Server compiler detected.
  5. JVM version is 25.151-b12
  6. using thread-local object allocation.
  7. Parallel GC with 4 thread(s)
  8. Heap Configuration: #堆内存配置信息
  9. MinHeapFreeRatio = 0
  10. MaxHeapFreeRatio = 100
  11. MaxHeapSize = 4259315712 (4062.0MB)
  12. NewSize = 88604672 (84.5MB)
  13. MaxNewSize = 1419771904 (1354.0MB)
  14. OldSize = 177733632 (169.5MB)
  15. NewRatio = 2
  16. SurvivorRatio = 8
  17. MetaspaceSize = 21807104 (20.796875MB)
  18. CompressedClassSpaceSize = 1073741824 (1024.0MB)
  19. MaxMetaspaceSize = 17592186044415 MB
  20. G1HeapRegionSize = 0 (0.0MB)
  21. Heap Usage: # 堆内存的使用情况
  22. PS Young Generation #年轻代
  23. Eden Space:
  24. capacity = 66584576 (63.5MB)
  25. used = 32076464 (30.590499877929688MB)
  26. free = 34508112 (32.90950012207031MB)
  27. 48.17401555579478% used
  28. From Space:
  29. capacity = 11010048 (10.5MB)
  30. used = 10987608 (10.478599548339844MB)
  31. free = 22440 (0.02140045166015625MB)
  32. 99.79618617466518% used
  33. To Space:
  34. capacity = 11010048 (10.5MB)
  35. used = 0 (0.0MB)
  36. free = 11010048 (10.5MB)
  37. 0.0% used
  38. PS Old Generation #年老代
  39. capacity = 177733632 (169.5MB)
  40. used = 4062192 (3.8740081787109375MB)
  41. free = 173671440 (165.62599182128906MB)
  42. 2.2855505479120577% used
  43. 13795 interned Strings occupying 1879808 bytes.

3.2 查看内存中对象数量及大小

  1. #查看所有对象,包括活跃以及非活跃的
  2. jmap histo <pid> | more
  3. #查看活跃对象
  4. jmap histo:live <pid> | more
  5. C:\Users\CYJ>jmap -histo:live 11728 | more
  6. num #instances #bytes class name
  7. ----------------------------------------------
  8. 1: 35487 6423112 [C
  9. 2: 1969 1971024 [B
  10. 3: 34061 817464 java.lang.String
  11. 4: 5945 523160 java.lang.reflect.Method
  12. 5: 15932 509824 java.util.HashMap$Node
  13. 6: 3535 402416 java.lang.Class
  14. 7: 4154 243528 [Ljava.lang.Object;
  15. 8: 1863 201384 [I
  16. 9: 1252 190912 [Ljava.util.HashMap$Node;
  17. 10: 5934 189888 java.util.concurrent.ConcurrentHashMap$Node
  18. 11: 4368 92240 [Ljava.lang.Class;
  19. 12: 1858 89184 java.util.HashMap
  20. 13: 1288 82800 [Ljava.lang.String;
  21. 14: 95 82192 [Ljava.util.concurrent.ConcurrentHashMap$Node;
  22. 15: 5082 81312 java.lang.Object
  23. 16: 1893 75720 java.util.LinkedHashMap$Entry
  24. 17: 738 59040 java.lang.reflect.Constructor
  25. 18: 143 54256 [Ljava.util.WeakHashMap$Entry;
  26. 19: 736 52992 java.lang.reflect.Field
  27. 20: 399 50888 [Ljava.lang.reflect.Method;
  28. 21: 1496 47872 java.util.Hashtable$Entry
  29. 22: 1089 43560 java.lang.ref.SoftReference
  30. 23: 1086 43440 java.util.TreeMap$Entry
  31. 24: 841 40368 org.apache.tomcat.util.modeler.AttributeInfo
  32. 25: 987 39480 java.lang.ref.Finalizer
  33. 26: 133 33672 [[C
  34. -- More --
  1. #对象说明
  2. B byte
  3. C char
  4. D double
  5. F float
  6. I int
  7. J long
  8. Z boolean
  9. [ 数组,如[I表示int[]
  10. [L+类名 其他对象

3.3 将内存使用情况dump到文件中

  1. #用法:
  2. jmap dump:format=b,file=dumpFileName <pid>
  3. #示例
  4. jmap dump:format=b,file=/tmp/dump.dat 11728

3.4 通过jhat对dump文件进行分析

  1. #用法:
  2. jhat port <port> <file>
  3. #示例:
  4. jhat port 9999 /tmp/dump.dat

3.5 通过MAT工具对dump文件进行分析

3.5.1 MAT工具介绍

  1. MAT(Memory Analyzer Tool),一个基于Eclipse的内存分析工具,是一个快速、功能丰富的JAVA heap分析工具,它可以帮助我们查找内存泄漏和减少内存消耗。使用内存分析工具从众多的对象中进行分析,快速的计算出在内存中对象的占用大小,看看是谁阻止了垃圾收集器的回收工作,并可以通过报表直观的查看到可能造成这种结果的对象。
  2. 官网地址:https://www.eclipse.org/mat/

3.5.2 下载安装

  1. 下载地址:https://www.eclipse.org/mat/downloads.php
  2. 下载解压

3.5.3使用

4.内存溢出的定位与分析

  1. 内存溢出在实际的生产环境中经常会遇到,比如,不断的将数据写入到一个集合中,出现了死循环,读取超大的文件等等,都可能会造成内存溢出。如果出现了内存溢出,首先我们需要定位到发生内存溢出的环节,并且进行分析,是正常还是非正常情况,如果是正常的需求,就应该考虑加大内存的设置,如果是非正常需求,那么就要对代码进行修改,修复这个bug。首先,我们得先学会如何定位问题,然后再进行分析。如何定位问题呢,我们需要借助于jmapMAT工具进行定位分析。

4.1模拟内存溢出

编写代码,向List集合中添加100万个字符串,每个字符串由1000个UUID组成。如果程序能够正常执行,最后打印ok。

  1. /**
  2. * @description:
  3. * @author: 大佬味的小男孩
  4. * @date: 2020-08-10 21:54
  5. **/
  6. public class TestJvmOutOfMemory {
  7. public static void main(String[] args) {
  8. List<Object> list = new ArrayList<>();
  9. for (int i = 0; i < 10000000; i++) {
  10. String str = "";
  11. for (int j = 0; j < 1000; j++) {
  12. str += UUID.randomUUID().toString();
  13. }
  14. list.add(str);
  15. }
  16. System.out.println("ok");
  17. }
  18. }

为了演示效果,我们将设置执行的参数,这里使用的是Idea编辑器。

2020-08-10_220125.png

可以看到,当发生内存溢出时,会dump文件到java_pid17672.hprof。

JVM优化篇章一 - 图4

4.2 导入到MAT工具中进行分析

JVM优化篇章一 - 图5

可以看到,有88.03%的内存由Object[]数组占有,所以比较可疑。
分析:这个可疑是正确的,因为已经有超过90%的内存都被它占有,这是非常有可能出现内存溢出的

JVM优化篇章一 - 图6

可以看到集合中存储了大量的uuid字符串。

5.jstack的使用

  1. 有些时候我们需要查看下jvm中的线程执行情况,比如,发现服务器的CPU的负载突然增高了、出现了死锁、死循环等,我们该如何分析呢?
  2. 由于程序是正常运行的,没有任何的输出,从日志方面也看不出什么问题,所以就需要看下jvm的内部线程的执行情况,然后再进行分析查找出原因。这个时候,就需要借助于jstack命令了,jstack的作用是将正在运行的jvm的线程情况进行快照,并且打印出来:
  1. #用法:jstack <pid>
  2. C:\Users\CYJ>jps
  3. 11568 org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
  4. 18384
  5. 19424 Jps
  6. 14920 Launcher
  7. 2024 KotlinCompileDaemon
  8. 6920 Bootstrap
  9. 18188 RemoteMavenServer
  10. C:\Users\CYJ>jstack 6920
  11. 2020-08-10 22:18:43
  12. Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.151-b12 mixed mode):
  13. "ajp-nio-8009-AsyncTimeout" #46 daemon prio=5 os_prio=0 tid=0x000000001eb4f800 nid=0x374c waiting on condition [0x00000000223cf000]
  14. java.lang.Thread.State: TIMED_WAITING (sleeping)
  15. at java.lang.Thread.sleep(Native Method)
  16. at org.apache.coyote.AbstractProtocol$AsyncTimeout.run(AbstractProtocol.java:1133)
  17. at java.lang.Thread.run(Thread.java:748)
  18. "ajp-nio-8009-Acceptor-0" #45 daemon prio=5 os_prio=0 tid=0x000000001eb44000 nid=0x2754 runnable [0x00000000222cf000]
  19. java.lang.Thread.State: RUNNABLE
  20. at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
  21. at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
  22. at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
  23. - locked <0x000000076f7c9740> (a java.lang.Object)
  24. at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:455)
  25. at java.lang.Thread.run(Thread.java:748)
  26. "ajp-nio-8009-ClientPoller-1" #44 daemon prio=5 os_prio=0 tid=0x000000001eb4b000 nid=0x21ac runnable [0x00000000221ce000]
  27. java.lang.Thread.State: RUNNABLE
  28. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  29. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  30. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  31. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  32. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  33. - locked <0x000000076c2d6708> (a sun.nio.ch.Util$3)
  34. - locked <0x000000076c2d66f8> (a java.util.Collections$UnmodifiableSet)
  35. - locked <0x000000076c2d65a8> (a sun.nio.ch.WindowsSelectorImpl)
  36. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  37. at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:796)
  38. at java.lang.Thread.run(Thread.java:748)
  39. "ajp-nio-8009-ClientPoller-0" #43 daemon prio=5 os_prio=0 tid=0x000000001eb42800 nid=0x4ac0 runnable [0x00000000220cf000]
  40. java.lang.Thread.State: RUNNABLE
  41. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  42. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  43. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  44. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  45. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  46. - locked <0x000000076c2d2580> (a sun.nio.ch.Util$3)
  47. - locked <0x000000076c2d2570> (a java.util.Collections$UnmodifiableSet)
  48. - locked <0x000000076c2d2420> (a sun.nio.ch.WindowsSelectorImpl)
  49. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  50. at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:796)
  51. at java.lang.Thread.run(Thread.java:748)
  52. "ajp-nio-8009-exec-10" #42 daemon prio=5 os_prio=0 tid=0x000000001eb49800 nid=0x3bb8 waiting on condition [0x0000000021fce000]
  53. java.lang.Thread.State: WAITING (parking)
  54. at sun.misc.Unsafe.park(Native Method)
  55. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  56. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  57. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  58. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  59. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  60. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  61. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  62. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  63. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  64. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  65. at java.lang.Thread.run(Thread.java:748)
  66. "ajp-nio-8009-exec-9" #41 daemon prio=5 os_prio=0 tid=0x000000001eb42000 nid=0x4780 waiting on condition [0x0000000021ecf000]
  67. java.lang.Thread.State: WAITING (parking)
  68. at sun.misc.Unsafe.park(Native Method)
  69. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  70. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  71. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  72. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  73. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  74. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  75. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  76. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  77. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  78. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  79. at java.lang.Thread.run(Thread.java:748)
  80. "ajp-nio-8009-exec-8" #40 daemon prio=5 os_prio=0 tid=0x000000001eb48800 nid=0x3588 waiting on condition [0x0000000021dce000]
  81. java.lang.Thread.State: WAITING (parking)
  82. at sun.misc.Unsafe.park(Native Method)
  83. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  84. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  85. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  86. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  87. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  88. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  89. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  90. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  91. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  92. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  93. at java.lang.Thread.run(Thread.java:748)
  94. "ajp-nio-8009-exec-7" #39 daemon prio=5 os_prio=0 tid=0x000000001eb41000 nid=0x4050 waiting on condition [0x0000000021ccf000]
  95. java.lang.Thread.State: WAITING (parking)
  96. at sun.misc.Unsafe.park(Native Method)
  97. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  98. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  99. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  100. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  101. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  102. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  103. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  104. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  105. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  106. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  107. at java.lang.Thread.run(Thread.java:748)
  108. "ajp-nio-8009-exec-6" #38 daemon prio=5 os_prio=0 tid=0x000000001eb47000 nid=0x38e8 waiting on condition [0x0000000021bce000]
  109. java.lang.Thread.State: WAITING (parking)
  110. at sun.misc.Unsafe.park(Native Method)
  111. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  112. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  113. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  114. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  115. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  116. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  117. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  118. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  119. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  120. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  121. at java.lang.Thread.run(Thread.java:748)
  122. "ajp-nio-8009-exec-5" #37 daemon prio=5 os_prio=0 tid=0x000000001eb43800 nid=0x174 waiting on condition [0x0000000021ace000]
  123. java.lang.Thread.State: WAITING (parking)
  124. at sun.misc.Unsafe.park(Native Method)
  125. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  126. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  127. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  128. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  129. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  130. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  131. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  132. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  133. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  134. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  135. at java.lang.Thread.run(Thread.java:748)
  136. "ajp-nio-8009-exec-4" #36 daemon prio=5 os_prio=0 tid=0x000000001eb46800 nid=0x44c4 waiting on condition [0x00000000219cf000]
  137. java.lang.Thread.State: WAITING (parking)
  138. at sun.misc.Unsafe.park(Native Method)
  139. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  140. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  141. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  142. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  143. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  144. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  145. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  146. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  147. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  148. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  149. at java.lang.Thread.run(Thread.java:748)
  150. "ajp-nio-8009-exec-3" #35 daemon prio=5 os_prio=0 tid=0x000000001eb45800 nid=0x472c waiting on condition [0x00000000218ce000]
  151. java.lang.Thread.State: WAITING (parking)
  152. at sun.misc.Unsafe.park(Native Method)
  153. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  154. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  155. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  156. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  157. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  158. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  159. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  160. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  161. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  162. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  163. at java.lang.Thread.run(Thread.java:748)
  164. "ajp-nio-8009-exec-2" #34 daemon prio=5 os_prio=0 tid=0x000000001eb45000 nid=0x3c48 waiting on condition [0x00000000217ce000]
  165. java.lang.Thread.State: WAITING (parking)
  166. at sun.misc.Unsafe.park(Native Method)
  167. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  168. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  169. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  170. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  171. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  172. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  173. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  174. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  175. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  176. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  177. at java.lang.Thread.run(Thread.java:748)
  178. "ajp-nio-8009-exec-1" #33 daemon prio=5 os_prio=0 tid=0x000000001eb48000 nid=0x5f4 waiting on condition [0x00000000216ce000]
  179. java.lang.Thread.State: WAITING (parking)
  180. at sun.misc.Unsafe.park(Native Method)
  181. - parking to wait for <0x000000076c2cf900> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  182. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  183. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  184. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  185. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  186. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  187. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  188. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  189. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  190. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  191. at java.lang.Thread.run(Thread.java:748)
  192. "http-nio-8080-AsyncTimeout" #32 daemon prio=5 os_prio=0 tid=0x000000001ea5e000 nid=0x1128 waiting on condition [0x00000000215cf000]
  193. java.lang.Thread.State: TIMED_WAITING (sleeping)
  194. at java.lang.Thread.sleep(Native Method)
  195. at org.apache.coyote.AbstractProtocol$AsyncTimeout.run(AbstractProtocol.java:1133)
  196. at java.lang.Thread.run(Thread.java:748)
  197. "http-nio-8080-Acceptor-0" #31 daemon prio=5 os_prio=0 tid=0x000000001ea5d800 nid=0x1620 runnable [0x00000000214cf000]
  198. java.lang.Thread.State: RUNNABLE
  199. at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
  200. at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
  201. at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
  202. - locked <0x000000076f7c8408> (a java.lang.Object)
  203. at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:455)
  204. at java.lang.Thread.run(Thread.java:748)
  205. "http-nio-8080-ClientPoller-1" #30 daemon prio=5 os_prio=0 tid=0x000000001ea5c000 nid=0xea8 runnable [0x00000000213cf000]
  206. java.lang.Thread.State: RUNNABLE
  207. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  208. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  209. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  210. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  211. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  212. - locked <0x000000076c2c3898> (a sun.nio.ch.Util$3)
  213. - locked <0x000000076c2c3888> (a java.util.Collections$UnmodifiableSet)
  214. - locked <0x000000076c2c3738> (a sun.nio.ch.WindowsSelectorImpl)
  215. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  216. at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:796)
  217. at java.lang.Thread.run(Thread.java:748)
  218. "http-nio-8080-ClientPoller-0" #29 daemon prio=5 os_prio=0 tid=0x000000001ea60800 nid=0x4aec runnable [0x00000000212cf000]
  219. java.lang.Thread.State: RUNNABLE
  220. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  221. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  222. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  223. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  224. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  225. - locked <0x000000076c2bf6a0> (a sun.nio.ch.Util$3)
  226. - locked <0x000000076c2bf690> (a java.util.Collections$UnmodifiableSet)
  227. - locked <0x000000076c2bf540> (a sun.nio.ch.WindowsSelectorImpl)
  228. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  229. at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:796)
  230. at java.lang.Thread.run(Thread.java:748)
  231. "http-nio-8080-exec-10" #28 daemon prio=5 os_prio=0 tid=0x000000001ea5f000 nid=0x1e00 waiting on condition [0x00000000211ce000]
  232. java.lang.Thread.State: WAITING (parking)
  233. at sun.misc.Unsafe.park(Native Method)
  234. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  235. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  236. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  237. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  238. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  239. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  240. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  241. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  242. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  243. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  244. at java.lang.Thread.run(Thread.java:748)
  245. "http-nio-8080-exec-9" #27 daemon prio=5 os_prio=0 tid=0x000000001ea59800 nid=0x1cec waiting on condition [0x00000000210ce000]
  246. java.lang.Thread.State: WAITING (parking)
  247. at sun.misc.Unsafe.park(Native Method)
  248. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  249. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  250. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  251. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  252. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  253. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  254. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  255. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  256. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  257. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  258. at java.lang.Thread.run(Thread.java:748)
  259. "http-nio-8080-exec-8" #26 daemon prio=5 os_prio=0 tid=0x000000001ea5c800 nid=0x8b4 waiting on condition [0x0000000020fce000]
  260. java.lang.Thread.State: WAITING (parking)
  261. at sun.misc.Unsafe.park(Native Method)
  262. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  263. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  264. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  265. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  266. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  267. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  268. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  269. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  270. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  271. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  272. at java.lang.Thread.run(Thread.java:748)
  273. "http-nio-8080-exec-7" #25 daemon prio=5 os_prio=0 tid=0x000000001ea5b000 nid=0x2f88 waiting on condition [0x0000000020ece000]
  274. java.lang.Thread.State: WAITING (parking)
  275. at sun.misc.Unsafe.park(Native Method)
  276. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  277. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  278. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  279. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  280. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  281. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  282. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  283. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  284. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  285. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  286. at java.lang.Thread.run(Thread.java:748)
  287. "http-nio-8080-exec-6" #24 daemon prio=5 os_prio=0 tid=0x000000001ea5f800 nid=0x2798 waiting on condition [0x0000000020dce000]
  288. java.lang.Thread.State: WAITING (parking)
  289. at sun.misc.Unsafe.park(Native Method)
  290. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  291. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  292. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  293. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  294. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  295. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  296. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  297. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  298. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  299. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  300. at java.lang.Thread.run(Thread.java:748)
  301. "http-nio-8080-exec-5" #23 daemon prio=5 os_prio=0 tid=0x000000001ea5a800 nid=0x2ec8 waiting on condition [0x0000000020ccf000]
  302. java.lang.Thread.State: WAITING (parking)
  303. at sun.misc.Unsafe.park(Native Method)
  304. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  305. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  306. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  307. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  308. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  309. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  310. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  311. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  312. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  313. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  314. at java.lang.Thread.run(Thread.java:748)
  315. "http-nio-8080-exec-4" #22 daemon prio=5 os_prio=0 tid=0x000000001eaa4000 nid=0x4190 waiting on condition [0x0000000020bcf000]
  316. java.lang.Thread.State: WAITING (parking)
  317. at sun.misc.Unsafe.park(Native Method)
  318. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  319. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  320. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  321. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  322. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  323. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  324. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  325. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  326. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  327. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  328. at java.lang.Thread.run(Thread.java:748)
  329. "http-nio-8080-exec-3" #21 daemon prio=5 os_prio=0 tid=0x000000001edc6800 nid=0x414c waiting on condition [0x0000000020ace000]
  330. java.lang.Thread.State: WAITING (parking)
  331. at sun.misc.Unsafe.park(Native Method)
  332. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  333. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  334. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  335. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  336. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  337. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  338. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  339. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  340. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  341. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  342. at java.lang.Thread.run(Thread.java:748)
  343. "http-nio-8080-exec-2" #20 daemon prio=5 os_prio=0 tid=0x000000001edc5800 nid=0x4b98 waiting on condition [0x00000000209ce000]
  344. java.lang.Thread.State: WAITING (parking)
  345. at sun.misc.Unsafe.park(Native Method)
  346. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  347. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  348. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  349. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  350. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  351. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  352. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  353. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  354. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  355. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  356. at java.lang.Thread.run(Thread.java:748)
  357. "http-nio-8080-exec-1" #19 daemon prio=5 os_prio=0 tid=0x000000001edc5000 nid=0x4064 waiting on condition [0x00000000208ce000]
  358. java.lang.Thread.State: WAITING (parking)
  359. at sun.misc.Unsafe.park(Native Method)
  360. - parking to wait for <0x000000076c24f638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  361. at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  362. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  363. at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
  364. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
  365. at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
  366. at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
  367. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
  368. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  369. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  370. at java.lang.Thread.run(Thread.java:748)
  371. "ContainerBackgroundProcessor[StandardEngine[Catalina]]" #18 daemon prio=5 os_prio=0 tid=0x000000001edc0800 nid=0x4bcc waiting on condition [0x00000000207cf000]
  372. java.lang.Thread.State: TIMED_WAITING (sleeping)
  373. at java.lang.Thread.sleep(Native Method)
  374. at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1357)
  375. at java.lang.Thread.run(Thread.java:748)
  376. "NioBlockingSelector.BlockPoller-2" #15 daemon prio=5 os_prio=0 tid=0x000000001e683000 nid=0x215c runnable [0x000000002001f000]
  377. java.lang.Thread.State: RUNNABLE
  378. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  379. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  380. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  381. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  382. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  383. - locked <0x000000076f593270> (a sun.nio.ch.Util$3)
  384. - locked <0x000000076f593280> (a java.util.Collections$UnmodifiableSet)
  385. - locked <0x000000076f5931f0> (a sun.nio.ch.WindowsSelectorImpl)
  386. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  387. at org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller.run(NioBlockingSelector.java:298)
  388. "NioBlockingSelector.BlockPoller-1" #14 daemon prio=5 os_prio=0 tid=0x000000001e682000 nid=0x3530 runnable [0x000000001ff1f000]
  389. java.lang.Thread.State: RUNNABLE
  390. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
  391. at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
  392. at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
  393. at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
  394. at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
  395. - locked <0x000000076f59b270> (a sun.nio.ch.Util$3)
  396. - locked <0x000000076f59b280> (a java.util.Collections$UnmodifiableSet)
  397. - locked <0x000000076f59b1f0> (a sun.nio.ch.WindowsSelectorImpl)
  398. at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
  399. at org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller.run(NioBlockingSelector.java:298)
  400. "GC Daemon" #13 daemon prio=2 os_prio=-2 tid=0x000000001e2db800 nid=0x3034 in Object.wait() [0x000000001fc1e000]
  401. java.lang.Thread.State: TIMED_WAITING (on object monitor)
  402. at java.lang.Object.wait(Native Method)
  403. - waiting on <0x000000076f593408> (a sun.misc.GC$LatencyLock)
  404. at sun.misc.GC$Daemon.run(GC.java:117)
  405. - locked <0x000000076f593408> (a sun.misc.GC$LatencyLock)
  406. "AsyncFileHandlerWriter-789451787" #12 daemon prio=5 os_prio=0 tid=0x000000001d592800 nid=0x1a68 waiting on condition [0x000000001e04f000]
  407. java.lang.Thread.State: TIMED_WAITING (parking)
  408. at sun.misc.Unsafe.park(Native Method)
  409. - parking to wait for <0x000000076f593598> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
  410. at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
  411. at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
  412. at java.util.concurrent.LinkedBlockingDeque.pollFirst(LinkedBlockingDeque.java:522)
  413. at java.util.concurrent.LinkedBlockingDeque.poll(LinkedBlockingDeque.java:684)
  414. at org.apache.juli.AsyncFileHandler$LoggerThread.run(AsyncFileHandler.java:160)
  415. "Service Thread" #9 daemon prio=9 os_prio=0 tid=0x000000001bffe800 nid=0x2640 runnable [0x0000000000000000]
  416. java.lang.Thread.State: RUNNABLE
  417. "C1 CompilerThread2" #8 daemon prio=9 os_prio=2 tid=0x000000001bfcb800 nid=0x2bf0 waiting on condition [0x0000000000000000]
  418. java.lang.Thread.State: RUNNABLE
  419. "C2 CompilerThread1" #7 daemon prio=9 os_prio=2 tid=0x000000001bfc7000 nid=0x3ce0 waiting on condition [0x0000000000000000]
  420. java.lang.Thread.State: RUNNABLE
  421. "C2 CompilerThread0" #6 daemon prio=9 os_prio=2 tid=0x000000001d492800 nid=0x8c8 waiting on condition [0x0000000000000000]
  422. java.lang.Thread.State: RUNNABLE
  423. "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001bfb2800 nid=0x2e04 waiting on condition [0x0000000000000000]
  424. java.lang.Thread.State: RUNNABLE
  425. "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001bfb1800 nid=0x3070 runnable [0x0000000000000000]
  426. java.lang.Thread.State: RUNNABLE
  427. "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x000000001bf8f000 nid=0x1ae4 in Object.wait() [0x000000001d2ee000]
  428. java.lang.Thread.State: WAITING (on object monitor)
  429. at java.lang.Object.wait(Native Method)
  430. - waiting on <0x000000076f5d88d0> (a java.lang.ref.ReferenceQueue$Lock)
  431. at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
  432. - locked <0x000000076f5d88d0> (a java.lang.ref.ReferenceQueue$Lock)
  433. at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
  434. at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
  435. "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000002a15800 nid=0x332c in Object.wait() [0x000000001d1ee000]
  436. java.lang.Thread.State: WAITING (on object monitor)
  437. at java.lang.Object.wait(Native Method)
  438. - waiting on <0x000000076f5d8b00> (a java.lang.ref.Reference$Lock)
  439. at java.lang.Object.wait(Object.java:502)
  440. at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
  441. - locked <0x000000076f5d8b00> (a java.lang.ref.Reference$Lock)
  442. at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
  443. "main" #1 prio=5 os_prio=0 tid=0x0000000002922800 nid=0x35a8 runnable [0x00000000025ae000]
  444. java.lang.Thread.State: RUNNABLE
  445. at java.net.DualStackPlainSocketImpl.accept0(Native Method)
  446. at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
  447. at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
  448. at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
  449. - locked <0x000000076c2dc850> (a java.net.SocksSocketImpl)
  450. at java.net.ServerSocket.implAccept(ServerSocket.java:545)
  451. at java.net.ServerSocket.accept(ServerSocket.java:513)
  452. at org.apache.catalina.core.StandardServer.await(StandardServer.java:466)
  453. at org.apache.catalina.startup.Catalina.await(Catalina.java:769)
  454. at org.apache.catalina.startup.Catalina.start(Catalina.java:715)
  455. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  456. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  457. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  458. at java.lang.reflect.Method.invoke(Method.java:498)
  459. at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
  460. at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
  461. "VM Thread" os_prio=2 tid=0x000000001bf67800 nid=0x4218 runnable
  462. "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002937000 nid=0x4b8c runnable
  463. "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000002938800 nid=0x4548 runnable
  464. "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x000000000293b000 nid=0x3290 runnable
  465. "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x000000000293c800 nid=0x1714 runnable
  466. "VM Periodic Task Thread" os_prio=2 tid=0x000000001d533000 nid=0x3060 waiting on condition
  467. JNI global references: 243

5.1 线程的状态

JVM优化篇章一 - 图7

在Java中线程的状态一共被分成6种:

  1. 初始态(NEW
  2. 创建一个Thread对象,但还未调用start()启动线程时,线程处于初始态。
  3. 运行态(RUNNABLE),在Java中,运行态包括 就绪态 运行态。
  4. 就绪态
  5. 该状态下的线程已经获得执行所需的所有资源,只要CPU分配执行权就能运行。
  6. 所有就绪态的线程存放在就绪队列中。
  7. 运行态
  8. 获得CPU执行权,正在执行的线程。
  9. 由于一个CPU同一时刻只能执行一条线程,因此每个CPU每个时刻只有一条运行态的线程。
  10. 阻塞态(BLOCKED
  11. 当一条正在执行的线程请求某一资源失败时,就会进入阻塞态。
  12. 而在Java中,阻塞态专指请求锁失败时进入的状态。
  13. 由一个阻塞队列存放所有阻塞态的线程。
  14. 处于阻塞态的线程会不断请求资源,一旦请求成功,就会进入就绪队列,等待执行。
  15. 等待态(WAITING
  16. 当前线程中调用waitjoinpark函数时,当前线程就会进入等待态。
  17. 也有一个等待队列存放所有等待态的线程。
  18. 线程处于等待态表示它需要等待其他线程的指示才能继续运行。
  19. 进入等待态的线程会释放CPU执行权,并释放资源(如:锁)
  20. 超时等待态(TIMED_WAITING
  21. 当运行中的线程调用sleep(time)、waitjoinparkNanosparkUntil时,就会进入该状态;
  22. 它和等待态一样,并不是因为请求不到资源,而是主动进入,并且进入后需要其他线程唤醒;
  23. 进入该状态后释放CPU执行权 占有的资源。
  24. 与等待态的区别:到了超时时间后自动进入阻塞队列,开始竞争锁。
  25. 终止态(TERMINATED
  26. 线程执行结束后的状态。

5.2 死锁问题

如果在生产环境发生了死锁,我们将看到的是部署的程序没有任何反应了,这个时候我们可以借助jstack进行分析,下面我们实战下查找死锁的原因。

5.2.1 构造死锁

编写代码,启动2个线程,Thread1拿到了obj1锁,准备去拿obj2锁时,obj2已经被Thread2锁定,所以发生死锁。

  1. /**
  2. * @description:
  3. * @author: 大佬味的小男孩
  4. * @date: 2020-08-10 22:32
  5. **/
  6. public class TestDeadLock {
  7. private static Object obj1 = new Object();
  8. private static Object obj2 = new Object();
  9. private static class Thread1 implements Runnable {
  10. @Override
  11. public void run() {
  12. synchronized (obj1) {
  13. System.out.println("Thread1 拿到了 obj1 的锁!");
  14. try {
  15. // 停顿2秒的意义在于,让Thread2线程拿到obj2的锁
  16. Thread.sleep(2000);
  17. } catch (InterruptedException e) {
  18. e.printStackTrace();
  19. }
  20. synchronized (obj2) {
  21. System.out.println("Thread1 拿到了 obj2 的锁!");
  22. }
  23. }
  24. }
  25. }
  26. private static class Thread2 implements Runnable {
  27. @Override
  28. public void run() {
  29. synchronized (obj2) {
  30. System.out.println("Thread2 拿到了 obj2 的锁!");
  31. try {
  32. Thread.sleep(2000);
  33. } catch (InterruptedException e) {
  34. e.printStackTrace();
  35. }
  36. synchronized (obj1) {
  37. System.out.println("Thread2 拿到了 obj1 的锁!");
  38. }
  39. }
  40. }
  41. }
  42. public static void main(String[] args) {
  43. new Thread(new Thread1()).start();
  44. new Thread(new Thread2()).start();
  45. }
  46. }

5.2.2 使用jstack进行分析

  1. C:\Users\CYJ>jps
  2. 18384
  3. 13368 Jps
  4. 16552 TestDeadLock
  5. 2024 KotlinCompileDaemon
  6. 13308 Launcher
  7. 18188 RemoteMavenServer
  8. C:\Users\CYJ>jstack 16552
  9. 2020-08-10 22:37:30
  10. Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.151-b12 mixed mode):
  11. "DestroyJavaVM" #13 prio=5 os_prio=0 tid=0x00000000016de000 nid=0xd9c waiting on condition [0x0000000000000000]
  12. java.lang.Thread.State: RUNNABLE
  13. "Thread-1" #12 prio=5 os_prio=0 tid=0x000000001e017800 nid=0x20d0 waiting for monitor entry [0x000000001ecdf000]
  14. java.lang.Thread.State: BLOCKED (on object monitor)
  15. at cn.TestDeadLock$Thread2.run(TestDeadLock.java:41)
  16. - waiting to lock <0x000000076b7870c8> (a java.lang.Object)
  17. - locked <0x000000076b7870d8> (a java.lang.Object)
  18. at java.lang.Thread.run(Thread.java:748)
  19. "Thread-0" #11 prio=5 os_prio=0 tid=0x000000001e012800 nid=0x2b50 waiting for monitor entry [0x000000001ebdf000]
  20. java.lang.Thread.State: BLOCKED (on object monitor)
  21. at cn.TestDeadLock$Thread1.run(TestDeadLock.java:24)
  22. - waiting to lock <0x000000076b7870d8> (a java.lang.Object)
  23. - locked <0x000000076b7870c8> (a java.lang.Object)
  24. at java.lang.Thread.run(Thread.java:748)
  25. "Service Thread" #10 daemon prio=9 os_prio=0 tid=0x000000001df9e800 nid=0x1d88 runnable [0x0000000000000000]
  26. java.lang.Thread.State: RUNNABLE
  27. "C1 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x000000001df99000 nid=0x2b34 waiting on condition [0x0000000000000000]
  28. java.lang.Thread.State: RUNNABLE
  29. "C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000001df37000 nid=0x21fc waiting on condition [0x0000000000000000]
  30. java.lang.Thread.State: RUNNABLE
  31. "C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x000000001df33000 nid=0x20e8 waiting on condition [0x0000000000000000]
  32. java.lang.Thread.State: RUNNABLE
  33. "Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000001df22800 nid=0x4b74 runnable [0x000000001e5de000]
  34. java.lang.Thread.State: RUNNABLE
  35. at java.net.SocketInputStream.socketRead0(Native Method)
  36. at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
  37. at java.net.SocketInputStream.read(SocketInputStream.java:171)
  38. at java.net.SocketInputStream.read(SocketInputStream.java:141)
  39. at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
  40. at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
  41. at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
  42. - locked <0x000000076b8c99e0> (a java.io.InputStreamReader)
  43. at java.io.InputStreamReader.read(InputStreamReader.java:184)
  44. at java.io.BufferedReader.fill(BufferedReader.java:161)
  45. at java.io.BufferedReader.readLine(BufferedReader.java:324)
  46. - locked <0x000000076b8c99e0> (a java.io.InputStreamReader)
  47. at java.io.BufferedReader.readLine(BufferedReader.java:389)
  48. at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)
  49. "Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x000000001cb2f000 nid=0x4270 waiting on condition [0x0000000000000000]
  50. java.lang.Thread.State: RUNNABLE
  51. "Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x000000001cb2e000 nid=0xd18 runnable [0x0000000000000000]
  52. java.lang.Thread.State: RUNNABLE
  53. "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000003547800 nid=0x1d04 in Object.wait() [0x000000001de7f000]
  54. java.lang.Thread.State: WAITING (on object monitor)
  55. at java.lang.Object.wait(Native Method)
  56. - waiting on <0x000000076b608ec8> (a java.lang.ref.ReferenceQueue$Lock)
  57. at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
  58. - locked <0x000000076b608ec8> (a java.lang.ref.ReferenceQueue$Lock)
  59. at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
  60. at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
  61. "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000003542000 nid=0x3730 in Object.wait() [0x000000001dd7f000]
  62. java.lang.Thread.State: WAITING (on object monitor)
  63. at java.lang.Object.wait(Native Method)
  64. - waiting on <0x000000076b606b68> (a java.lang.ref.Reference$Lock)
  65. at java.lang.Object.wait(Object.java:502)
  66. at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
  67. - locked <0x000000076b606b68> (a java.lang.ref.Reference$Lock)
  68. at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
  69. "VM Thread" os_prio=2 tid=0x000000001cae7800 nid=0x2214 runnable
  70. "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000003468000 nid=0x35a0 runnable
  71. "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000003469800 nid=0x3dcc runnable
  72. "GC task thread#2 (ParallelGC)" os_prio=0 tid=0x000000000346b000 nid=0x2204 runnable
  73. "GC task thread#3 (ParallelGC)" os_prio=0 tid=0x000000000346c800 nid=0x2864 runnable
  74. "VM Periodic Task Thread" os_prio=2 tid=0x000000001e00d800 nid=0x3484 waiting on condition
  75. JNI global references: 33
  76. Found one Java-level deadlock:
  77. =============================
  78. "Thread-1":
  79. waiting to lock monitor 0x000000001cb0d7e8 (object 0x000000076b7870c8, a java.lang.Object),
  80. which is held by "Thread-0"
  81. "Thread-0":
  82. waiting to lock monitor 0x000000001cb101d8 (object 0x000000076b7870d8, a java.lang.Object),
  83. which is held by "Thread-1"
  84. Java stack information for the threads listed above:
  85. ===================================================
  86. "Thread-1":
  87. at cn.TestDeadLock$Thread2.run(TestDeadLock.java:41)
  88. - waiting to lock <0x000000076b7870c8> (a java.lang.Object)
  89. - locked <0x000000076b7870d8> (a java.lang.Object)
  90. at java.lang.Thread.run(Thread.java:748)
  91. "Thread-0":
  92. at cn.TestDeadLock$Thread1.run(TestDeadLock.java:24)
  93. - waiting to lock <0x000000076b7870d8> (a java.lang.Object)
  94. - locked <0x000000076b7870c8> (a java.lang.Object)
  95. at java.lang.Thread.run(Thread.java:748)
  96. Found 1 deadlock.

在输出的信息中,已经看到,发现了1个死锁,关键看这个。

  1. "Thread-1":
  2. at cn.TestDeadLock$Thread2.run(TestDeadLock.java:41)
  3. - waiting to lock <0x000000076b7870c8> (a java.lang.Object)
  4. - locked <0x000000076b7870d8> (a java.lang.Object)
  5. at java.lang.Thread.run(Thread.java:748)
  6. "Thread-0":
  7. at cn.TestDeadLock$Thread1.run(TestDeadLock.java:24)
  8. - waiting to lock <0x000000076b7870d8> (a java.lang.Object)
  9. - locked <0x000000076b7870c8> (a java.lang.Object)
  10. at java.lang.Thread.run(Thread.java:748)
  1. 可以清晰的看到:
  2. Thread2获取了 <0x000000076b7870d8> 的锁,等待获取 <0x000000076b7870c8>这个锁
  3. Thread1获取了 <0x000000076b7870c8> 的锁,等待获取 <0x000000076b7870d8>这个锁
  4. 由此可见,发生了死锁。

6.VisualVM工具的使用

  1. VisualVM,能够监控线程,内存情况,查看方法的CPU时间和内存中的对 象,已被GC的对象,反向查看分配的堆栈(如100String对象分别由哪几个对象分配出来的)。
  2. VisualVM使用简单,几乎0配置,功能还是比较丰富的,几乎囊括了其它JDK自带命令的所有功能。
  3. 内存信息
  4. 线程信息
  5. Dump堆(本地进程)
  6. Dump线程(本地进程)
  7. 打开堆Dump。堆Dump可以用jmap来生成。
  8. 打开线程Dump
  9. 生成应用快照(包含内存信息、线程信息等等)
  10. 性能分析。CPU分析(各个方法调用时间,检查哪些方法耗时多),内存分析(各类对象占用的内存,检查哪些类占用内存多)

6.1 启动

在jdk的安装目录的bin目录下,找到jvisualvm.exe,双击打开即可。

JVM优化篇章一 - 图8

6.2 查看本地进程

6.3 查看CPU、内存、类、线程运行信息

JVM优化篇章一 - 图9

6.4 查看线程详情

JVM优化篇章一 - 图10

也可以点击右上角Dump按钮,将线程的信息导出,其实就是执行的jstack命令。

6.5 抽样器

JVM优化篇章一 - 图11

6.6 监控远程的jvm

VisualJVM不仅是可以监控本地jvm进程,还可以监控远程的jvm进程,需要借助于JMX技术实现。

6.6.1 什么是JMX?

JMX(Java Management Extensions,即Java管理扩展)是一个为应用程序、设备、系统等植入管理功能的框架。JMX可以跨越一系列异构操作系统平台、系统体系结构和网络传输协议,灵活的开发无缝集成的系统、网络和服务管理应用。

6.6.2 监控远程的tomcat

想要监控远程的tomcat,就需要在远程的tomcat进行对JMX配置,方法如下:

  1. #在tomcatbin目录下,修改catalina.sh,添加如下的参数
  2. JAVA_OPTS="‐Dcom.sun.management.jmxremote
  3. Dcom.sun.management.jmxremote.port=9999
  4. Dcom.sun.management.jmxremote.authenticate=false
  5. Dcom.sun.management.jmxremote.ssl=false"
  6. #这几个参数的意思是:
  7. #‐Dcom.sun.management.jmxremote :允许使用JMX远程管理
  8. #‐Dcom.sun.management.jmxremote.port=9999 JMX远程连接端口
  9. #‐Dcom.sun.management.jmxremote.authenticate=false :不进行身份认证,任何用户都可以连接
  10. #‐Dcom.sun.management.jmxremote.ssl=false :不使用ssl

6.6.3 使用VisualJVM连接远程tomcat