Stop method not getting called when terminating the windows service

I have converted a java application into a windows Service using procrun. When I stop the service using Windows Services program it gets hung and doesn't respond. When launch it using the debug mode and then when I terminate it using ctrl+c, I can't see the stop method being called. I have given a print statement which is not getting printed. Below is my code. Please advice. There is nothing in the Windows Even logs related to this service.

public static void main(String[] args) {
    if ("start".equals(args[0])) {
        start(args);
    } else if ("stop".equals(args[0])) {
        stop(args);
    }

}

public static void start(String[] args) {

    KubeSdkMain sdkMain = new KubeSdkMain();
    sdkMain.startSDK();

}

public static void stop(String[] args) {

    System.out.println("stop");
    stop = true;

}

Below is the content of the bat file I run for installing the service.

cd "G:\Projects"
set PR_PATH="G:\Projects"
SET PR_SERVICE_NAME=TestService
SET PR_JAR=KKSDK.jar
SET START_CLASS=com.example.test
SET START_METHOD=start
SET STOP_CLASS=com.example.test
SET STOP_METHOD=stop
rem ; separated values
SET STOP_PARAMS=0
rem ; separated values
SET JVM_OPTIONS=-Dapp.home=%PR_PATH%
prunsrv.exe //IS//%PR_SERVICE_NAME% --Install="%PR_PATH%\prunsrv.exe" --Jvm=auto --Startup=auto --StartMode=jvm --StartClass=%START_CLASS% --StartMethod=%START_METHOD% --StopMode=jvm --StopClass=%STOP_CLASS% --StopMethod=%STOP_METHOD% ++StopParams=%STOP_PARAMS% --Classpath="%PR_PATH%\%PR_JAR%" --DisplayName="%PR_SERVICE_NAME%" ++JvmOptions=%JVM_OPTIONS%

pause

Answers


I think you should use a shutdown hook so that when you press ctrl+c shutdown hook gets called. This link might help you ShutDownHook


Need Your Help

terminating with uncaught exception of type NSException .I have a Signal-Sigbrt error

ios objective-c xcode

I Followed other instructions but I don't know what's wrong. Check connections but everything seems alright.

How to change PHP extension in Codeigniter

php .htaccess codeigniter

I want to change index.php into index.abc (or index.aspx). I tried to change $config['index_page'], but can't. I only can remove index.php and add .abc behind url through $config['url_suffix'] = '....