1 一个web程序部署在tomcat程序中, 怎么让程序接受重启命令后重启
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
You can make an independent interface service and execute a start and stop script, so that you can achieve the effect you want
Directly use java to call the system command to restart tomcatThe code is probably like this:
public static void runShell(final String cmd) throws IOException, InterruptedException { executorService.execute(new Runnable() { @Override public void run() { try { Runtime run = Runtime.getRuntime(); Process p = run.exec(cmd); BufferedInputStream in = new BufferedInputStream(p.getInputStream()); BufferedReader inBr = new BufferedReader(new InputStreamReader(in)); String lineStr; while ((lineStr = inBr.readLine()) != null) { logger.info(lineStr);// 打印输出信息 } //检查命令是否执行失败。 if (p.waitFor() != 0) { if (p.exitValue() == 1) {// 0表示正常结束,1:非正常结束 logger.error(cmd + "命令执行失败!"); } } inBr.close(); in.close(); } catch (Exception e) { logger.error("调用系统命令失败!", e); } } }); }
Restarting the web program is nothing more than ending the process, executing the system exit 4 function, and then executing the main method to start the container. This program must be independent
You can make an independent interface service and execute a start and stop script, so that you can achieve the effect you want
Directly use java to call the system command to restart tomcat
The code is probably like this:
Restarting the web program is nothing more than ending the process, executing the system exit 4 function, and then executing the main method to start the container. This program must be independent