JAVA_OPTS

JAVA_OPTSJava Options可选参数,主要包括:性能、GC、调试等。

参数 说明
-server 区别与-client
-Xmx1152m 最大堆内存
-Xms1152m 最小堆内存与最大保持一致,避免gc后重新分配
-Xss128K 线程栈,默认1M
-Xmn256m 年轻代,JVM内存=年轻代+年老代+永久代
-XX:PermSize=128m 永久代初始内存
-XX:MaxPermSize=128m 永久代最大内存,默认64M
-XX:NewRatio=4 设置年轻代(包括Eden和两个Survivor区)/与年老代的比值(除去持久代),设置为4,则年轻代与年老代所占比值为1:4
-XX:SurvivorRatio=4 年轻代中Eden/Survivor
-XX:MaxGCPauseMillis = 200 暂停时间目标
–XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/home/admin/logs/gc.log -XX:+PrintHeapAtGC 打印GC日志
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false 开启jmx
-XX:+UseG1GC G1垃圾回收器,年轻代GC:youngGC,年老带GC:fullGC ,降低youngGC的频率、减少fullGC的次数

GC-log

{Heap before GC invocations=1 (full 0):
 garbage-first heap   total 1179648K, used 58298K [0x00000000b8000000, 0x00000000b8102400, 0x0000000100000000)
  region size 1024K, 57 young (58368K), 4 survivors (4096K)
 Metaspace       used 10984K, capacity 11220K, committed 11392K, reserved 1058816K
  class space    used 1315K, capacity 1390K, committed 1408K, reserved 1048576K
2018-07-06T17:37:20.044+0800: 4.079: [GC pause (G1 Evacuation Pause) (young), 0.0212402 secs]
   [Parallel Time: 9.4 ms, GC Workers: 1]
      [GC Worker Start (ms):  4079.2]
      [Ext Root Scanning (ms):  2.0]
      [Update RS (ms):  0.0]
         [Processed Buffers:  0]
      [Scan RS (ms):  0.1]
      [Code Root Scanning (ms):  0.7]
      [Object Copy (ms):  6.5]
      [Termination (ms):  0.0]
         [Termination Attempts:  1]
      [GC Worker Other (ms):  0.0]
      [GC Worker Total (ms):  9.3]
      [GC Worker End (ms):  4088.4]
   [Code Root Fixup: 0.2 ms]
   [Code Root Purge: 0.0 ms]
   [Clear CT: 0.0 ms]
   [Other: 11.5 ms]
      [Choose CSet: 0.0 ms]
      [Ref Proc: 11.1 ms]
      [Ref Enq: 0.0 ms]
      [Redirty Cards: 0.0 ms]
      [Humongous Register: 0.0 ms]
      [Humongous Reclaim: 0.0 ms]
      [Free CSet: 0.1 ms]
   [Eden: 53.0M(53.0M)->0.0B(52.0M) Survivors: 4096.0K->5120.0K Heap: 56.9M(1152.0M)->4608.0K(1152.0M)]
Heap after GC invocations=2 (full 0):
 garbage-first heap   total 1179648K, used 4607K [0x00000000b8000000, 0x00000000b8102400, 0x0000000100000000)
  region size 1024K, 5 young (5120K), 5 survivors (5120K)
 Metaspace       used 10984K, capacity 11220K, committed 11392K, reserved 1058816K
  class space    used 1315K, capacity 1390K, committed 1408K, reserved 1048576K
}
 [Times: user=0.02 sys=0.00, real=0.02 secs]

更多:

[1] http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

[2] https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html#CBBIJCHG