prunsrv.exe是如何工作的?

时间:2016-08-22 14:10:13

标签: java apache-commons prunsrv

按照教程(https://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/)使用prunsrv.exe按照预期在Windows上运行,配置jvm模式java服务。但问题是prunsrv.exe如何停止并启动服务。我正在使用开始和停止方法中的线程ID将日志打印到文件中,如下所示。

 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”仍然是静态布尔值,它们仍然是不同的过程(对吗?)。这是如何运作的?

1 个答案:

答案 0 :(得分:1)

也许......我不知道.... prunsrv在新线程(例如“thread1”)中调用了带有选项start的main函数,并且听了下一个命令。当您停止服务时,prunsrv在新线程(例如“thread2”)中调用带有选项stop的main函数。 prunsrvthread1thread2有共同记忆。

相关问题