日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JVM 核心技术 调优分析与面试经验

發布時間:2024/10/6 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JVM 核心技术 调优分析与面试经验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.GC分析類

import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.LongAdder; /* 演示GC日志生成與解讀 */ public class GCLogAnalysis {private static Random random = new Random();public static void main(String[] args) {// 當前毫秒時間戳long startMillis = System.currentTimeMillis();// 持續運行毫秒數; 可根據需要進行修改long timeoutMillis = TimeUnit.SECONDS.toMillis(1);// 結束時間戳long endMillis = startMillis + timeoutMillis;LongAdder counter = new LongAdder();System.out.println("正在執行...");// 緩存一部分對象; 進入老年代int cacheSize = 2000;Object[] cachedGarbage = new Object[cacheSize];// 在此時間范圍內,持續循環while (System.currentTimeMillis() < endMillis) {// 生成垃圾對象Object garbage = generateGarbage(100*1024);counter.increment();int randomIndex = random.nextInt(2 * cacheSize);if (randomIndex < cacheSize) {cachedGarbage[randomIndex] = garbage;}}System.out.println("執行結束!共生成對象次數:" + counter.longValue());}// 生成對象private static Object generateGarbage(int max) {int randomSize = random.nextInt(max);int type = randomSize % 4;Object result = null;switch (type) {case 0:result = new int[randomSize];break;case 1:result = new byte[randomSize];break;case 2:result = new double[randomSize];break;default:StringBuilder builder = new StringBuilder();String randomString = "randomString-Anything";while (builder.length() < randomSize) {builder.append(randomString);builder.append(max);builder.append(randomSize);}result = builder.toString();break;}return result;} }

2.編譯執行GC分析類

javac -encoding utf-8 GCLogAnalysis.java java GCLogAnalysis 正在執行... 執行結束!共生成對象次數:7746

在控制臺打印日志信息

java -XX:+PrintGCDetails GCLogAnalysis 正在執行... [GC (Allocation Failure) [PSYoungGen: 49152K->7663K(56832K)] 49152K->17184K(186880K), 0.2004381 secs] [Times: user=0.00 sys=0.06, real=0.22 secs] [GC (Allocation Failure) [PSYoungGen: 56750K->7674K(105984K)] 66271K->33109K(236032K), 0.0088254 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] [GC (Allocation Failure) [PSYoungGen: 105955K->7661K(105984K)] 131391K->66334K(236032K), 0.0156307 secs] [Times: user=0.02 sys=0.03, real=0.01 secs] [GC (Allocation Failure) [PSYoungGen: 105965K->7677K(204288K)] 164638K->105454K(334336K), 0.0168545 secs] [Times: user=0.06 sys=0.00, real=0.02 secs] [Full GC (Ergonomics) [PSYoungGen: 7677K->0K(204288K)] [ParOldGen: 97776K->96280K(201728K)] 105454K->96280K(406016K), [Metaspace: 2713K->2713K(1056768K)], 0.0196829 secs] [Times: user=0.06 sys=0.00, real=0.02 secs] [GC (Allocation Failure) [PSYoungGen: 196608K->7678K(204288K)] 292888K->162201K(406016K), 0.0207846 secs] [Times: user=0.06 sys=0.00, real=0.02 secs] [Full GC (Ergonomics) [PSYoungGen: 7678K->0K(204288K)] [ParOldGen: 154522K->146814K(294912K)] 162201K->146814K(499200K), [Metaspace: 2713K->2713K(1056768K)], 0.0316279 secs] [Times: user=0.03 sys=0.00, real=0.03 secs] [GC (Allocation Failure) [PSYoungGen: 196017K->57322K(370688K)] 342832K->204136K(665600K), 0.0176191 secs] [Times: user=0.02 sys=0.02, real=0.02 secs] [GC (Allocation Failure) [PSYoungGen: 370666K->78847K(413696K)] 517480K->288396K(708608K), 0.0427564 secs] [Times: user=0.05 sys=0.13, real=0.04 secs] [GC (Allocation Failure) [PSYoungGen: 413175K->123891K(594944K)] 622724K->367967K(889856K), 0.0552594 secs] [Times: user=0.08 sys=0.11, real=0.06 secs] [Full GC (Ergonomics) [PSYoungGen: 123891K->0K(594944K)] [ParOldGen: 244076K->265452K(435200K)] 367967K->265452K(1030144K), [Metaspace: 2713K->2713K(1056768K)], 0.0547824 secs] [Times: user=0.16 sys=0.02, real=0.06 secs] 執行結束!共生成對象次數:5450 HeapPSYoungGen total 594944K, used 118753K [0x0000000780b80000, 0x00000007b6800000, 0x00000007c0000000)eden space 471040K, 25% used [0x0000000780b80000,0x0000000787f78658,0x000000079d780000)from space 123904K, 0% used [0x00000007a7480000,0x00000007a7480000,0x00000007aed80000)to space 160768K, 0% used [0x000000079d780000,0x000000079d780000,0x00000007a7480000)ParOldGen total 435200K, used 265452K [0x0000000702200000, 0x000000071cb00000, 0x0000000780b80000)object space 435200K, 60% used [0x0000000702200000,0x000000071253b0b0,0x000000071cb00000)Metaspace used 2719K, capacity 4486K, committed 4864K, reserved 1056768Kclass space used 297K, capacity 386K, committed 512K, reserved 1048576K

總結

以上是生活随笔為你收集整理的JVM 核心技术 调优分析与面试经验的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。