编写要求: (1)关闭现有JAR包,重新启动JAR包。 (2)编写JAR包重启的脚本文件,同时重启多个JAR包,设置排序时间,不要同一时刻重启,防止服务系统卡顿,导致业务中断。
@echo off
set port=8911
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port
taskkill /pid %%m -t -f
goto start
)
:start
START "xxxxxx.jar 8911" java -jar -Dfile.encoding=utf-8 xxxxxx.jar & ping localhost -n 5
set port=8001
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do (
echo kill the process %%m who use the port
taskkill /pid %%m -t -f
goto start
)
:start
START "xxxxxx.jar 8001" java -jar -Dfile.encoding=utf-8 xxxxxx.jar & ping localhost -n 10
pause
脚本执行后,jar启动卡住,需要按Enter回车键才行。
解决办法: