0
根据教程(https://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/)使用在Windows上运行的prunsrv.exe按预期配置了jvm模式java服务。但问题是prunsrv.exe如何停止并启动服务。我打印日志文件与线程ID在开始和停止方法如下。prunsrv.exe是如何工作的?
private static boolean stop = false;
public static void main(String[] args)
{
log.debug(Integer.toHexString(System.identityHashCode(Thread.currentThread())));
if (args.length == 0) {
log.debug("no args provided, give start/stop as argument");
return;
}
String mode = args[0];
if ("start".equals(mode)) {
log.debug("start " + Integer.toHexString(System.identityHashCode(Thread.currentThread())));
startService(args);
} else if ("stop".equals(mode)) {
log.debug("stop " + Integer.toHexString(System.identityHashCode(Thread.currentThread())));
stopService(args);
}
log.debug("End of main " + Integer.toHexString(System.identityHashCode(Thread.currentThread())));
}
这是下面的输出日志(启动和停止服务)
22/Aug/2016 19:22:00,962- App: 441772e
22/Aug/2016 19:22:00,962- App: start 441772e
22/Aug/2016 19:22:00,962- App: startService
22/Aug/2016 19:23:21,259- App: 1ef37254
22/Aug/2016 19:23:21,259- App: stop 1ef37254
22/Aug/2016 19:23:21,259- App: stopService
22/Aug/2016 19:23:21,259- App: End of main 1ef37254
22/Aug/2016 19:23:22,181- App: End of main 441772e
正如我们所看到的线程是不同的,这意味着一个新的进程开始于启动服务和停止服务。尽管变量“stop”是一个静态布尔值,但它们是不同的过程(右?)。这个怎么用?