startup.sh
#!/bin/bash
nohup java -Djava.security.egd=file:/dev/./urandom -Xms512m -Xmx512m -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/javadump -jar payment.jar > payment.log 2>&1 & echo $! > payment.pid
停止
kill -9 `cat payment.pid`
参数说明
Djava.security.egd:非阻塞的熵源,随机数生成方法。
-Xms128m:初始堆大小为2048M。
-Xmx128m:最大堆大小为2048M。
-XX:MetaspaceSize:这个参数是初始化的Metaspace大小,该值越大触发Metaspace GC的时机就越晚。随着GC的到来,虚拟机会根据实际情况调控Metaspace的大小,可能增加上线也可能降低。在默认情况下,这个值大小根据不同的平台在12M到20M浮动。使用java -XX:+PrintFlagsInitial命令查看本机的初始化参数,-XX:Metaspacesize为21810376B(大约20.8M)。
-XX:MaxMetaspaceSize:这个参数用于限制Metaspace增长的上限,防止因为某些情况导致Metaspace无限的使用本地内存,影响到其他程序。在本机上该参数的默认值为4294967295B(大约4096MB)。
元空间(Metaspace):一个新的内存空间的诞生,与 Oracle JRockit 和 IBM JVM类似,JDK 8.HotSpot JVM开始使用本地化的内存存放类的元数据,这个空间叫做元空间(Metaspace)。
-XX:+
HeapDumpOnOutOfMemoryError:内存溢出时生成heapdump文件。
-XX:HeapDumpPath=/var/log/javadump :内存溢出后,heapdump文件存放的位置。
其他参考参数:
-Xmn:64M:新生代的内存为64M。
-XX:SurvivorRatio=2:比例:Eden/From。
-XX:NewRatio=2:比例:老年代/新生代。
-XX:PermSize=10M:方法区(永久代)内存大小。
-XX:MaxPermSize=10M:方法区(永久代)内存最大为10M。
-XX:MaxDirectMemorySize:直接内存设置,如果不指定,则默认与Java堆最大值(-Xmx指定)一样。
-XX:+PrintGCDetails:查看GC日志。
-XX:+UseSerialGC:配置串行回收器。
-XX:+PrintCommandLineFlags:可以将隐式或者显示传给虚拟机的参数输出。
# jps -v
# jinfo `cat payment.pid`
Attaching to process ID 16339, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.271-b09
Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.271-b09
sun.boot.library.path = /usr/java/jdk1.8.0_271-amd64/jre/lib/amd64
java.protocol.handler.pkgs = org.springframework.boot.loader
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
user.dir = /root/payment
java.vm.specification.name = Java Virtual machine Specification
PID = 16339
java.runtime.version = 1.8.0_271-b09
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/java/jdk1.8.0_271-amd64/jre/lib/endorsed
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-1160.25.1.el7.x86_64
user.home = /root
user.timezone = Asia/Shanghai
catalina.useNaming = false
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
@AppId = application
java.specification.version = 1.8
catalina.home = /tmp/Tomcat.9999.8487203950517193557
user.name = root
java.class.path = payment.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = payment.jar
java.home = /usr/java/jdk1.8.0_271-amd64/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_271
java.ext.dirs = /usr/java/jdk1.8.0_271-amd64/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/java/jdk1.8.0_271-amd64/jre/lib/resources.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/rt.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/sunrsasign.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/jsse.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/jce.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/charsets.jar:/usr/java/jdk1.8.0_271-amd64/jre/lib/jfr.jar:/usr/java/jdk1.8.0_271-amd64/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
catalina.base = /tmp/tomcat.9999.8487203950517193557
file.separator = /
java.security.egd = file:/dev/./urandom
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.cpu.isalist =
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:CompressedClassSpaceSize=125829120 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=536870912 -XX:MaxHeapSize=536870912 -XX:MaxMetaspaceSize=134217728 -XX:MaxNewSize=178782208 -XX:MetaspaceSize=134217728 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=178782208 -XX:OldSize=358088704 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
Command line: -Djava.security.egd=file:/dev/./urandom -Xms512m -Xmx512m -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/javadump