当前位置:网站首页>JVM Basics - > how to troubleshoot JVM problems in your project
JVM Basics - > how to troubleshoot JVM problems in your project
2022-06-12 22:09:00 【Ouhuang xiaodezi】
How to check your project JVM problem
For those who are still in normal operation ⾏ The system of :
Through the results of each command , perhaps jvisualvm etc. ⼯ Come and go ⾏ analysis
You can make ⽤jmap Check it out. JVM The of each area in the ⽤ situation
Can pass jstack To view the operation of the thread ⾏ situation ,⽐ Such as which threads block 、 Is there a deadlock
Can pass jstat Command to view garbage collection , especially fullgc, If you find that fullgc⽐ More frequently , Then you have to go into ⾏ Tuned
⾸ First , Initial speculation is frequent
fullgc( In the old days, large-scale garbage collection was carried out )WhyIf you send it frequently ⽣fullgc however ⼜⼀ straight
No memory overflow occurred, The system is running wellSo expressed gc It's actually
You can recycle many objects at once, So it's best that these objects canyounggc( A new generation of garbage collection )In the process, it is recycled directly , Avoid these objects from entering ⼊ To ⽼ years , Even in the permanent zoneIn this case , It's time to see why
- Consider these
Survival time is not ⻓ Is the object of ⽐ a ⼤, The young generation cannot let go , Direct entry ⼊ here we are ⽼ years , Try to add ⼤ Young generation ⼤ Small - Check which thread is using too much memory
- Check which thread accounts for ⽤CPU That's too much , Positioning to specific ⽅ Law , Optimize this ⽅ The enforcement of law ⾏, See if you can avoid the creation of some objects , from ⽽ Save memory
- Consider these
For those who have sent ⽣ 了
OOM( out of memory )The system of :
⼀ like ⽣ The production system will set when the system sends ⽣ 了 OOM when ,⽣ Become the... Of the time dump⽂ Pieces of
- XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/base
We can benefit from ⽤jsisualvm( visualization ) etc. ⼯ To analyze dump⽂ Pieces of
according to dump⽂ An exception instance object was found , And exception threads ( Occupy ⽤CPU⾼), Go to the specific code
Then go in again. ⾏ Detailed analysis and commissioning
JVM View details graphically
- The graphical interface can go to jdk Of bin Find below
jvisualvm.exe-> This is a built-in graphical interface- There are some easy-to-use plug-ins you can try to install
Visual GCbtrace
View threads 
View the memory and used by each thread cpu The situation of 
Check garbage collection 
see dump Tracking information 
JVM Command view details
jps-> Java ps: See what's running Java process
jps: You can list running
Java process, And display the name of the virtual machine execution main class and the process idC:\>jps 5932 test CollectionCommon options :
jps -ljps -vjps -l-> Output the full class name of the main class , If the process is executing Jar package , Output jar The name of the bagC:\>jps -l 5932 rod. aggregate . test Collectionjps -v-> Specified when the program starts jvm Parameters5932 test Collection -agentlib:jdwp=transport=dt_socket, address=127.0.0.1:54731, suspend=y, server=n -javaagent:C:\Users\ Ouhuang xiaodezi \AppData\Local\JetBrains\IntelliJIdea2021.2\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8
jstack-> Java stack: Print thread snapshot
View a certain Java In progress
Status of all threads.Generally used
The cause of the long pause in the positioning thread, Such as There is a cycle of life and death , Deadlock , Request external resources to wait for a long time etc. !Common options :
jstack process idjps -vjstack process id-> The state of all threads in the process , As long as the program is still going , Just print the track[C:\~]$ jstack 37476 2022-02-22 19:17:04 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.231-b11 mixed mode): "DestroyJavaVM" #24 prio=5 os_prio=0 tid=0x0000000002f94000 nid=0x8a40 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "myThreadB" #23 prio=5 os_prio=0 tid=0x0000000025314000 nid=0x5018 waiting for monitor entry [0x00000000266bf000] java.lang.Thread.State: BLOCKED (on object monitor) at rod.TestMain.lambda$main$1(TestMain.java:35) - waiting to lock <0x0000000743a6a820> (a java.lang.Object) - locked <0x0000000743a6a830> (a java.lang.Object) at rod.TestMain$$Lambda$2/1349414238.run(Unknown Source) at java.lang.Thread.run(Thread.java:748) "myThreadA" #22 prio=5 os_prio=0 tid=0x0000000025313000 nid=0x2794 waiting for monitor entry [0x00000000265bf000] java.lang.Thread.State: BLOCKED (on object monitor) at rod.TestMain.lambda$main$0(TestMain.java:21) - waiting to lock <0x0000000743a6a830> (a java.lang.Object) - locked <0x0000000743a6a820> (a java.lang.Object) at rod.TestMain$$Lambda$1/1873653341.run(Unknown Source) at java.lang.Thread.run(Thread.java:748) "Service Thread" #21 daemon prio=9 os_prio=0 tid=0x0000000024ff1000 nid=0x8cc4 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE ... "VM Thread" os_prio=2 tid=0x00000000215f7000 nid=0x8710 runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002faa800 nid=0x9378 runnable ... Find a Java Level deadlock : ============================= "myThreadB": Wait to lock the monitor 0x0000000021601c08 (object 0x0000000743a6a820, a java.lang.Object), This is from "myThreadA" "myThreadA": Wait to lock the monitor 0x0000000021604338 (object 0x0000000743a6a830, a java.lang.Object), This is from "myThreadB" Of the threads listed Java Stack information : =================================================== "myThreadB": at rod.TestMain.lambda$main$1(TestMain.java:35) - waiting to lock <0x0000000743a6a820> (a java.lang.Object) - locked <0x0000000743a6a830> (a java.lang.Object) at rod.TestMain$$Lambda$2/1349414238.run(Unknown Source) at java.lang.Thread.run(Thread.java:748) "myThreadA": at rod.TestMain.lambda$main$0(TestMain.java:21) - waiting to lock <0x0000000743a6a830> (a java.lang.Object) - locked <0x0000000743a6a820> (a java.lang.Object) at rod.TestMain$$Lambda$1/1873653341.run(Unknown Source) at java.lang.Thread.run(Thread.java:748)You may see some thread tracks :
DestroyJavaVM-> Destruction of the thread **(RUNNABLE= Running state )**myThreadB , myThreadA-> We define the thread directly **(BLOCKED= Blocked state )**Service Thread-> There are many other namesdaemonSo is the daemon threadRunning stateLet's not listGC-> Garbage collection thread **(RUNNABLE= Running state )**
And at the end, it indicates the location of the deadlock
jmap-> Java map: Export heap memory image file
jmap It is mainly used to export
Heap memory image file , See if there is a memory leaketc. .- out of memory : The memory is full , Fried , You also have to create new objects , Direct explosion ->
Overflow is easy to remember , It's full , The reverse is leakage - Memory leak : The memory is not full , however
There is a lot of garbage that can be recycled but can't be recycled, Standing in the manger
- out of memory : The memory is full , Fried , You also have to create new objects , Direct explosion ->
The production environment will generally
Configure the following parameters, Let the virtual machine be in OOM Auto generate after exception dump file- Dump File is process Of Memory image . You can put the program's Execution status adopt The debugger Save to dump In file .
- It is mainly used in the system
An exception or crash occursTime to generate dump file - And then use
Debugger to debug, In this way, the dump Copy the file to your own development machine - Debugging can find the location of the program error .
// Output error heap Dump Information route /Users/peng -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/Users/pengExecute the following command
Manual acquisition dump filejmap -dump:file= file name .dump process id
jstat-> java stat: see jvm Statistics
jstat Can be displayed
Local or remote virtual machineIn processClass loading 、 Memory 、 garbage collection 、 JIT( compiler ) compileEtcuse jstat Take a look at the class loading information . Personally, I rarely use this command ,
Viewing garbage collection information from the command line is not as convenient as viewing the graphical interface[C:\~]$ jstat -class 37476 Number of loaded classes Number of bytes to load class Number of unloaded classes The number of bytes to unload the class Time spent Loaded Bytes Unloaded Bytes Time 661 1285.3 0 0.0 0.17
give the thumbs-up , handsome young man !!!
边栏推荐
- Kotlin collaboration process - flow
- 2022-02-28 incluxdb high availability planning
- 生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
- Digraph deep copy
- [machine learning] learning notes 01- introduction
- SQL tuning guide notes 18:analyzing statistics using optimizer statistics Advisor
- 【QNX Hypervisor 2.2 用户手册】4.2 支持的构建环境
- [medium] 78 Subset (backtracking shall be supplemented later)
- JVisualVM初步使用
- [Jianzhi offer] Jianzhi offer 05 Replace spaces
猜你喜欢

leetcodeSQL:574. Elected

数据库每日一题---第10天:组合两个表

Dolphin-2.0.3 cluster deployment document

SQL tuning guide notes 17:importing and exporting optimizer statistics

【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)

设计消息队列存储消息数据的 MySQL 表格

SQL tuning guide notes 16:managing historical optimizer statistics

SQL tuning guide notes 14:managing extended statistics

Ansible playbook and ansible roles (III)

建立高可用的数据库
随机推荐
Ansible playbook和Ansible Roles(三)
Mr. Sun's version of JDBC (21:34:25, June 12, 2022)
Jin AI her power | impact tech, she can
OceanBase 社区版 OCP 功能解读
Afraid to write documents? AI plug-in for automatically generating code documents
【QNX Hypervisor 2.2 用户手册】4.4 构建Host
June training (day 10) - bit operation
【图像去噪】基于三边滤波器实现图像去噪附matlab代码
Can tonghuashun open an account? Is it safe to open an account in tonghuashun? How to open a securities account
talent showing itself! Oceanbase was selected into the 2021 "sci tech innovation China" open source innovation list
2022-02-28 incluxdb high availability planning
PCB package download website recommendation and detailed usage
MySQL introduction and installation (I)
IPhone: save Boolean into core data - iphone: save Boolean into core data
List of open source alternative projects of world famous Cloud Service SaaS companies
Permission to query execution plan in Oracle Database
Cloning PDB with ADG standby
Okio source code analysis
微信小程序提现功能
June training (day 12) - linked list