Does prunsrv.exe use multiple threads to run a Java application as a service?

4.6k Views Asked by At

Configured a jvm mode Java Windows service following this tutorial: (https://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/). I am printing log messages by thread ID to a file in the start and stop methods as follows:

 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())));
    }

This is the log output showing the services starting and stopping:

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

The threads IDs appear in the log file which indicates that a new process is started for start service and stop service. Even though the variable stop is a private static boolean the log file shows that the service are different process (Right?). So, why are multiple Windows processes being created to start and stop my service?

1

There are 1 best solutions below

0
On

I dont know.... Maybe, prunsrv called main function with option start in new thread ("thread1" for example), and listened in the next command. When you stop service, prunsrv called main function with option stop in new thread ("thread2" for example). prunsrv, thread1 and thread2 have common memory.