linux下啟動JAVA程序的腳本程序
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:可以將隱式或者顯示傳給虛擬機的參數輸出。
查看Java運行時情況
# 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