jvmこのチュートリアルに従ってモード Java Windows サービスを構成しました: ( https://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/ )。次のように、start メソッドと stop メソッドでスレッド 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
スレッド ID がログ ファイルに表示されます。これは、サービスの開始とサービスの停止のために新しいプロセスが開始されたことを示します。変数stopはprivate static booleanログファイルですが、サービスが異なるプロセスであることを示しています(そうですか?)。では、サービスを開始および停止するために複数の Windows プロセスが作成されるのはなぜですか?