Quirk Running Java as a Windows Service

I ran into a painful quirk of running a Java application server as a Windows Server service today.

The Windows Resource Kit provides a utility called “instsrv.exe” which can be used to set up another executable as a windows service. The quirk I ran into is that when you log out of your windows session, the service goes down. I need the service to stay UP.

In order to remedy this problem, the solution is to instruct instsrv.exe to start the JVM with the -Xrs option.

This option actually prevents the JMV from being terminated even when it receives the quit signal from the OS. The OS still wants to shutdown the JVM, but the JVM in effect says “no.” The OS sends a quit signal to the service which in turns passes it on to the JVM, which says “no.” So the option is being used as intended in an embedded JVM scenario (which Sun does document.)

The next step would to set up the service not to shutdown or to not pass along the quit signal to the JVM.

The only negative side effect I can think of with the –Xrs setup is that the Java application might not be exiting cleanly when it is really time to quit.

Note that –Xrs is only supported by Sun’s Java VMs. Other vendors may provide a similar option.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s