JVM 调优实战--一个案例理解常用工具(命令)
生活随笔
收集整理的這篇文章主要介紹了
JVM 调优实战--一个案例理解常用工具(命令)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
測試代碼
import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit;/*** 從數(shù)據(jù)庫中讀取信用數(shù)據(jù),套用模型,并把結(jié)果進(jìn)行記錄和傳輸*/public class T15_FullGC_Problem01 {private static class CardInfo {BigDecimal price = new BigDecimal(0.0);String name = "張三";int age = 5;Date birthdate = new Date();public void m() {}}private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(50,new ThreadPoolExecutor.DiscardOldestPolicy());public static void main(String[] args) throws Exception {executor.setMaximumPoolSize(50);for (;;){modelFit();Thread.sleep(100);}}private static void modelFit(){List<CardInfo> taskList = getAllCardInfo();taskList.forEach(info -> {// do somethingexecutor.scheduleWithFixedDelay(() -> {//do sth with infoinfo.m();}, 2, 3, TimeUnit.SECONDS);});}private static List<CardInfo> getAllCardInfo(){List<CardInfo> taskList = new ArrayList<>();for (int i = 0; i < 100; i++) {CardInfo ci = new CardInfo();taskList.add(ci);}return taskList;} }java -Xms200M -Xmx200M com.mashibing.jvm.gc.T15_FullGC_Problem01
top命令觀察到問題:內(nèi)存不斷增長 CPU占用率居高不下
jps定位具體java進(jìn)程
jinfo pid
jstat -gc 動態(tài)觀察gc情況 / 閱讀GC日志發(fā)現(xiàn)頻繁GC / arthas觀察 / jconsole jstat -gc 4655 500 : 每個500個毫秒打印GC的情況
jmap - histo 4655 | head -20,查找有多少對象產(chǎn)生
jmap -dump:format=b,file=xxx pid / jmap -histo
java -Xms20M -Xmx20M -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError com.mashibing.jvm.gc.T15_FullGC_Problem01
使用MAT / jhat進(jìn)行dump文件分析 https://www.cnblogs.com/baihuitestsoftware/articles/6406271.html
找到代碼的問題
總結(jié)
以上是生活随笔為你收集整理的JVM 调优实战--一个案例理解常用工具(命令)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JVM 调优实战--什么是调优及如何调优
- 下一篇: JVM 调优实战--jvisualvm远