Monday, January 14, 2008

Graceful Shutdown

JVM has a shutdownHook Runtime.getRuntime.addShutdownHook(Thread) which allows us to register a shutdown hook. However, it doesn't work well with Windows. It responds to CTRL-C, but doesn't react when the process is killed (from task manager, or service console). In Linux/Unix it does work.

So an alternate is to add stop handling in JavaService, which run java class as NT service, and provides an adaptor layer .

licAgentService.exe -install "HiPath Wireless License Agent" %EMS_JAVA_HOME%\bin\client\jvm.dll
-Xms16m -Xmx64m
-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8100,suspend=n
-start com.siemens.bk.lic.bootstrap.Main
-stop com.siemens.bk.lic.bootstrap.Main -method systemExit
-out .\logs\stdout.log
-err .\logs\stderr.log
-current %LICAGENT_HOME%
-depends "License Agent","HiPath Wireless RMI"

With the debug option, we can debug a service too.
In Windows Registry \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\, we can review all the option settings of the service.

No comments: