标签:循环 存储目录 stat red plain 显示 关闭 name log
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { String restartCmd = "nohup java -jar xxx.jar"; Thread.sleep(10000);//等10秒,保证分身启动完成后,再关掉自己 logger.debug("程序重启完成!"); } catch (Exception e) { logger.error("重启失败,原因:", e); } }});logger.debug("程序准备重启!");System.exit(0); |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import org.apache.logging.log4j.*;import java.io.BufferedReader;import java.io.InputStreamReader;public final class RuntimeUtil { private static Logger logger = LogManager.getLogger(); public static String exec(String command) { StringBuilder sb = new StringBuilder(); try { Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } process.getOutputStream().close(); reader.close(); process.destroy(); } catch (Exception e) { logger.error("执行外部命令错误,命令行:" + command, e); } return sb.toString(); } public static String jps() { return exec("jps -l"); }} |
|
1
2
3
4
5
6
7
|
public static String getJarExecPath(Class clazz) { String path = clazz.getProtectionDomain().getCodeSource().getLocation().getPath(); if (OSUtil.getOSname().equals(OSType.Windows)) { return path.substring(1); } return path;} |
OSUtil代码从这里获取
标签:循环 存储目录 stat red plain 显示 关闭 name log
原文地址:http://www.cnblogs.com/tuojunjie/p/7390855.html