查看java版本
java -version
java 自带命令
jps、jinfo、jstat、jmap、jstack、javac、javap......
使用jps查看本地启动的java程序,以及查看启动的配置命令
[root@/]#jps 653899 jar 664440 Jps #查看帮助 [root@/]#jps -h illegal argument: -h usage: jps [-help] jps [-q] [-mlvV] [] Definitions: : [: ] [root@/]# jps -mlvV 653899 javaApplication.jar --server.port=8081 -Xms256m -Xmx256m -Xss256k -XX:+UseParallelOldGC 664616 sun.tools.jps.Jps -mlvV -Denv.class.path=.:/usr/java/jdk/lib/dt.jar:/usr/java/jdk/lib/tools.jar -Dapplication.home=/usr/java/jdk -Xms8m
使用jinfo查看使用的各项配置
[root@/]# jinfo 653899 ....太长了省略啦,,,,,,虚拟机详细信息 [root@lanbaba /]# jinfo -h Usage: jinfo [option](to connect to running process) jinfo [option] (to connect to a core file) jinfo [option] [server_id@] (to connect to remote debug server) where
使用jstat查看垃圾回收情况
#查看GC回收情况 [root@/]# jstat -gc 653899 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 5632.0 5632.0 1056.0 0.0 75776.0 44086.2 175104.0 73553.5 81752.0 78912.3 10584.0 9993.1 70 0.782 3 0.712 1.494 #查看个垃圾回收的分配空间大小 [root@/]# jstat -gccapacity 653899 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC 87040.0 87040.0 87040.0 5632.0 5632.0 75776.0 175104.0 175104.0 175104.0 175104.0 0.0 1120256.0 81752.0 0.0 1048576.0 10584.0 70 3 [root@/]# jstat -help Usage: jstat -help|-options jstat -
使用jmap查看堆栈信息以及dump信息
[root@/]# jmap -heap 653899 Attaching to process ID 653899, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.291-b10 using thread-local object allocation. Parallel GC with 1 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 268435456 (256.0MB) NewSize = 89128960 (85.0MB) MaxNewSize = 89128960 (85.0MB) OldSize = 179306496 (171.0MB) NewRatio = 2 SurvivorRatio = 8 metaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxmetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 77594624 (74.0MB) used = 63667456 (60.718017578125MB) free = 13927168 (13.281982421875MB) 82.05137510557432% used From Space: capacity = 5767168 (5.5MB) used = 1081344 (1.03125MB) free = 4685824 (4.46875MB) 18.75% used To Space: capacity = 5767168 (5.5MB) used = 0 (0.0MB) free = 5767168 (5.5MB) 0.0% used PS Old Generation capacity = 179306496 (171.0MB) used = 75318784 (71.82958984375MB) free = 103987712 (99.17041015625MB) 42.00560809576023% used 34204 interned Strings occupying 3833760 bytes. #生产hprof文件,可以用ftp传出再使用JProfile打开 [root@ testproject]# jmap -dump:format=b,file=dddd.hprof 653899 Dumping heap to /home/testproject/dddd.hprof ... Heap dump file created
使用jstack查看死锁情况
[root@ testproject]# jstack -h Usage: jstack [-l](to connect to running process) jstack -F [-m] [-l] (to connect to a hung process) jstack [-m] [-l] (to connect to a core file) jstack [-m] [-l] [server_id@] (to connect to a remote debug server) Options: -F to force a thread dump. Use when jstack does not respond (process is hung) -m to print both java and native frames (mixed mode) -l long listing. Prints additional information about locks -h or -help to print this help message [root@ testproject]# jstack -l 653899 2021-11-17 15:19:17 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.291-b10 mixed mode): "Attach Listener" #38 daemon prio=9 os_prio=0 tid=0x00007f3008052000 nid=0xa2675 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "DestroyJavaVM" #37 prio=5 os_prio=0 tid=0x00007f303400a800 nid=0x9fa4c waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "http-nio-8081-Acceptor-0" #35 daemon prio=5 os_prio=0 tid=0x00007f3035814800 nid=0x9fab8 runnable [0x00007f300671b000] java.lang.Thread.State: RUNNABLE at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:424) at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:252) - locked <0x00000000fc3e4f60> (a java.lang.Object) at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:448) at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:70) at org.apache.tomcat.util.net.Acceptor.run(Acceptor.java:95) at java.lang.Thread.run(Thread.java:748) Locked ownable synchronizers: - None
然后再根据实际项目的情况进行调优,例如选择合适的垃圾回收器或者调整合适比例的年轻代老年代大小等等。
常见垃圾回收器
串行回收器:Serial(新生代)、Serial Old(老年代)
并行回收器:ParNew(新生代)、Parallel Scavenge(新生代)、Parallel Old(老年代)
并发回收器:CMS(老年代)、G1(整合型)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)