java命令的模版:java [-options] -jar jarfile [args...]先贴一下我的简单的启动命令:java -Xms128m -Xmx256m -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8081,suspend=n -jar /data/app/test.jar --spring.profiles.active=dev &其中:-Xms128m 设置的是JVM堆最小内存为128m-Xmx256m 设置的是JVM堆最大内存为256m这里有个问题是-Xmx指定的内存不包括jvm运行中使用的本地内存,所以如果有NIO等涉及到本地内存的情况时,该java进程占用的总内存会超过-Xmx设定的数值-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8081,suspend=n设置debug模式,允许tomcat远程连接服务器调试,调试端口可指定,此处为8081/data/app/test.jar 指定需要执行的jar包的路径--spring.profiles.active=dev 设定SpringBoot运行环境为dev环境& 后台模式执行
续上两篇博客,这里对命令再次调整
#!/bin/bashTag="Application"MainClass="com.test.Application"Lib="/testboot/test/lib/"Log="/testboot/test/run.log"JVM="-server -Xms128m -Xmx128m -XX:PermSize=32M -XX:MaxNewSize=64m -XX:MaxPermSize=64m -Djava.awt.headless=true -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"echo $TagRETVAL="0"# See how we were called.function start() { echo $Log if [ ! -f $Log ]; then touch $Log fi nohup java $JVM -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass > $Log 2>&1 & tailf $Log}function stop() { pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') if [ "$pid" != "" ]; then echo -n "boot ( pid $pid) is running" echo echo -n $"Shutting down boot: " pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') if [ "$pid" != "" ]; then echo "kill boot process" kill -9 "$pid" fi else echo "boot is stopped" fi status}function status(){ pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}') #echo "$pid" if [ "$pid" != "" ]; then echo "boot is running,pid is $pid" else echo "boot is stopped" fi}function usage(){ echo "Usage: $0 {start|stop|restart|status}" RETVAL="2"}# See how we were called.RETVAL="0"case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) RETVAL="3" ;; status) status ;; *) usage ;;esacexit $RETVAL
JVM 相关配置说明:
java.awt.headless 模式
jvm的内存分布,参数配置 和 GC处理机制
JVM实用参数 CMS收集器
JVM参数设置、分析