当前位置:网站首页>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 !!!
边栏推荐
- SQL tuning guide notes 17:importing and exporting optimizer statistics
- February 27th
- Thread safe level
- Design a MySQL table for message queue to store message data
- Design and practice of Hudi bucket index in byte skipping
- Why is pain rating important?
- Build a highly available database
- 六月集训(第11天) —— 矩阵
- lambda表达式与流优化代码
- Prefix sum and difference
猜你喜欢
![[C language] data type occupation](/img/12/e0f9679076d89fb5bd993ee3c345bf.jpg)
[C language] data type occupation

Compiling process of OpenSSL and libevent on PC

How to prevent phishing emails? S/mime certificate to help!

建立高可用的数据库

SQL tuning guide notes 10:optimizer statistics concepts

Recommended Chinese font in the code input box of Oracle SQL developer

孙老师版本JDBC(2022年6月12日21:34:25)

SQL调优指南笔记6:Explaining and Displaying Execution Plans

Okio source code analysis

PCB package download website recommendation and detailed usage
随机推荐
[sword finger offer] sword finger offer 35 Replication of complex linked list
数据库每日一题---第10天:组合两个表
在同花顺开户证券安全吗,证券开户怎么开户流程
How to perform disaster recovery and recovery for kubernetes cluster? (22)
Palindrome linked list and linked list intersection problem (intersecting with Xinyi people) do you really know?
The kotlin coroutine -- coroutine context and exception propagation
SQL tuning guide notes 8:optimizer access paths
Recommended Chinese font in the code input box of Oracle SQL developer
My struggle: my years in foreign enterprises (1)
LNMP platform docking redis service
多线程模型下的生产者消费者模式
六月集训(第11天) —— 矩阵
SQL tuning guide notes 11:histograms
What is the difference between a user thread and a daemon thread?
[sword finger offer] sword finger offer 58 - ii Rotate string left
[qnx hypervisor 2.2 manuel de l'utilisateur] 4.2 environnement de construction pris en charge
2022-02-28 incluxdb high availability planning
[Jianzhi offer] Jianzhi offer 09 Implementing queues with two stacks
Ansible summary (VI)
Prefix sum and difference