Java新生代回收一瞥-垃圾回收用arthas看dashboard

效果

一直刷新列表生成新对象 "人工诱发垃圾回收"
看两次Memory里面的eden_space used 从136M变成1M

Memory                                       used           total          max            usage          GC
heap                                         253M           495M           1979M          12.78%         gc.copy.count                                       61
tenured_gen                                  110M           341M           1365M          8.12%          gc.copy.time(ms)                                    2096
eden_space                                   136M           136M           546M           24.91%         gc.marksweepcompact.count                           5
survivor_space                               6M             17M            68M            8.99%          gc.marksweepcompact.time(ms)                        1234
nonheap                                      212M           216M           -1             98.08%
codeheap_'non-nmethods'                      1M             4M             7M             20.05%
metaspace                                    140M           141M           -1             99.33%
codeheap_'profiled_nmethods'                 40M            40M            116M           34.55%
compressed_class_space                       14M            14M            1024M          1.42%
codeheap_'non-profiled_nmethods'             15M            15M            116M           13.34%
mapped                                       0K             0K             -              0.00%
direct                                       316M           316M           -              100.00%
mapped - 'non-volatile memory'               0K             0K             -              0.00%
Runtime
os.name                                                                                                  Linux
os.version                                                                                               6.8.0-90-generic
java.version                                                                                             24.0.1
java.home                                                                                                /opt/java/openjdk
systemload.average                                                                                       0.13
processors                                                                                               32
timestamp/uptime                                                                                         Fri Jan 23 10:37:51 CST 2026/689058s
ID       NAME                                                GROUP                     PRIORITY          STATE            %CPU             DELTA_TIME        TIME             INTERRUPTED       DAEMON
274      reactor-http-epoll-21                               main                      5                 RUNNABLE         0.87             0.008             0:0.313          false             true
248      parallel-30                                         main                      5                 WAITING          0.7              0.007             0:0.162          false             true
78       redisson-netty-7-2                                  main                      5                 RUNNABLE         0.46             0.004             0:6.164          false             false
24765    Timer-for-arthas-dashboard-17f047bb-e86a-456e-962d- system                    5                 RUNNABLE         0.44             0.004             0:0.041          false             true
24753    arthas-NettyHttpTelnetBootstrap-3-4                 system                    5                 RUNNABLE         0.36             0.003             0:0.051          false             true
82       redisson-netty-7-6                                  main                      5                 RUNNABLE         0.32             0.003             0:6.123          false             false
31       Notification Thread                                 system                    9                 RUNNABLE         0.16             0.001             0:0.118          false             true
85       redisson-netty-7-8                                  main                      5                 RUNNABLE         0.12             0.001             0:6.143          false             false
51       redisson-timer-6-1                                  main                      5                 TIMED_WAITING    0.05             0.000             4:37.761         false             false
76       redisson-timer-9-1                                  main                      5                 TIMED_WAITING    0.04             0.000             4:34.719         false             false
65       reactor-http-epoll-1                                main                      5                 RUNNABLE         0.04             0.000             0:0.601          false             true
66       Thread-6                                            main                      5                 WAITING          0.03             0.000             0:2.148          false             true
38       AsyncAppender-Worker-ASYNC_APP                      main                      5                 WAITING          0.02             0.000             0:0.573          false             true
19218    ForkJoinPool-1-worker-16                            CarrierThreads            5                 TIMED_WAITING    0.02             0.000             0:1.138          false             true
50       MaintenanceTimer-1-thread-1                         main                      5                 TIMED_WAITING    0.01             0.000             0:1.191          false             true
39       AsyncAppender-Worker-ASYNC_ERROR                    main                      5                 WAITING          0.01             0.000             0:0.217          false             true
11       Reference Handler                                   system                    10                RUNNABLE         0.01             0.000             0:0.027          false             true
32       Common-Cleaner                                      InnocuousThreadGroup      8                 TIMED_WAITING    0.01             0.000             0:0.680          false             true
96       workIdHolder-8-1768446835584                        main                      5                 TIMED_WAITING    0.01             0.000             0:27.964         false             false
95       Thread-7                                            main                      5                 TIMED_WAITING    0.0              0.000             0:19.333         false             true
12       Finalizer                                           system                    8                 WAITING          0.0              0.000             0:0.000          false             true
13       Signal Dispatcher                                   system                    9                 RUNNABLE         0.0              0.000             0:0.000          false             true
33       Cleaner-0                                           InnocuousThreadGroup      8                 TIMED_WAITING    0.0              0.000             0:0.711          false             true
35       Attach Listener                                     system                    9                 RUNNABLE         0.0              0.000             0:0.038          false             true
43       parallel-1                                          main                      5                 WAITING          0.0              0.000             0:0.470          false             true
44       parallel-2                                          main                      5                 WAITING          0.0              0.000             0:0.445          false             true
46       AsyncGetter-2-thread-1                              main                      5                 WAITING          0.0              0.000             0:0.180          false             true
Memory                                       used           total          max            usage          GC
heap                                         119M           495M           1979M          6.02%          gc.copy.count                                       62
tenured_gen                                  110M           341M           1365M          8.12%          gc.copy.time(ms)                                    2131
eden_space                                   1M             136M           546M           0.22%          gc.marksweepcompact.count                           5
survivor_space                               7M             17M            68M            10.58%         gc.marksweepcompact.time(ms)                        1234
nonheap                                      212M           216M           -1             98.06%
codeheap_'non-nmethods'                      1M             4M             7M             20.05%
metaspace                                    140M           141M           -1             99.34%
codeheap_'profiled_nmethods'                 40M            40M            116M           34.57%
compressed_class_space                       14M            14M            1024M          1.42%
codeheap_'non-profiled_nmethods'             15M            15M            116M           13.34%
mapped                                       0K             0K             -              0.00%
direct                                       316M           316M           -              100.00%
mapped - 'non-volatile memory'               0K             0K             -              0.00%

AI帮我分析

1. 抓捕“消失的瞬间”
刷新前:eden_space 是 136M (24.91%)。注意,这里的 total 也是 136M。这意味着 Eden 区已经顶到了天花板,处于“满载”状态。

刷新后:eden_space 变成了 1M (0.22%)。

发生了什么:当你持续刷新列表时,Spring Boot 会不断创建 DTO、数据库连接对象、JSON 序列化字符数组等。因为 Eden 区已经满了,JVM 此时触发了 Minor GC (gc.copy.count 从 61 变成了 62)。

2. 垃圾回收的“证据链”
回收了多少? Eden 区从 136M 掉到 1M,清理掉了约 135M 的临时对象。

花了多久? gc.copy.time 从 2096ms 变为 2131ms,说明这次清理只用了 35 毫秒。

幸存者搬家了吗? * survivor_space 从 6M 变到了 7M。这说明刷新产生的对象中,有 1M 左右的对象(可能是你的 Session、缓存或其他长生命周期对象)没被回收,而是按照 2.4 垃圾回收算法 里的“复制算法”,被搬到了 Survivor 区。

tenured_gen(老年代)依然是 110M。说明你的列表数据都是“朝生夕死”的,没有直接晋升到老年代。

命令

linux的docker里面

/tmp # java -jar arthas-boot.jar
[INFO] JAVA_HOME: /opt/java/openjdk
[INFO] arthas-boot version: 4.1.4
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 1 /app/app.jar
1
[INFO] arthas home: /root/.arthas/lib/4.1.5/arthas
[INFO] The target process already listen port 3658, skip attach.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'

wiki         https://arthas.aliyun.com/doc
tutorials    https://arthas.aliyun.com/doc/arthas-tutorials.html
version      4.1.5
main_class   /app/app.jar
pid          1
start_time   2026-01-15 11:13:33.854
current_time 2026-01-22 16:24:09.821

[arthas@1]$ dashboard -i 1000 -n 10000



posted @ 2026-01-23 10:36  liv_vil  阅读(6)  评论(0)    收藏  举报