Link to home
Start Free TrialLog in
Avatar of asugri
asugri

asked on

java.exe launched by SYSTEM/Windows Service got killed after user logoff

Hi there,

I want to run a java application at machine reboot and without interruption afterward.
A Windows service is written to start the java class.  java class runs fine at reboot
without any user login.  I can check from another machine over network.  After user
(without admin privilege) login, Windows Task Manager shows the service and java.exe
under user name SYSTEM from Processes tab.  At this point, the java class is still
up and running.  

However, the java class got killed after the user without admin privilege logs off.
I can check from another machine through network if the java application is
running or not.  Login again only see the Windows service (under user name SYSTEM)
launching the java class from Windows Task Manager.  But java.exe (initially also
under user name SYSTEM) is gone.

How to let the java class continue to run without interruption?   The OS is
XP Pro SP3.  Java JRE version is 1.6.0_16.

Your opinion is very much appreciated.
Avatar of Sharon Seth
Sharon Seth
Flag of India image

How does the service start/run the java class ? Can I see it pls
Sounds wrongly configured.  You should probably just use a service wrapper, e.g. http://wrapper.tanukisoftware.com/doc/english/download.jsp
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
However, I have not used it for various reasons. One of the things to deal with is the one you mentioned; a Java process will normally be killed when the user logs off.
That should not be the case:
http://wrapper.tanukisoftware.com/doc/english/faq.html#6
Correct; if you're using the tanuki (or probably other) wrappers, there is no logoff problem.

The questioner, however, was not using a wrapper, and neither am I. In that case, the solution is along the lines I indicated.
Avatar of asugri
asugri

ASKER

Thanks for all the tips.   I used java -Xrs to run the class and it stayed running with user logoff.
Avatar of asugri

ASKER

According to
http://superuser.com/questions/374147/java-services-stop-working-when-user-logs-out

You need to add the -Xrs flag to your java.exe command line to prevent the JVM from exiting when you log off an XP machine. The problem doesn't arise on Windows 7 (or Vista/Server 2008) because "Session 0 Isolation" prevents users from logging in (and thus logging off) Session 0, the place where services are run.
That will work but should probably be regarded as a kludge. It sounds like you have what is essentially a service, albeit written in Java. If so, it should probably be made as far as possible to behave as a proper service. That means one that responds in a proper way to signals from the OS and is not forced to remain running by ignoring them. For one thing, a robust solution would log such events normally and be portable to other environments without fear of breakage.

Of course, it's difficult to say exactly how far it misses an optimal solution without knowing the details (i.e. the source code) of the implementation of the -Xrs flag. I suspect it might be a case of that not being available, another instance of Java being somewhat less than 'open source'. I'd be happy to be told otherwise, if any of you know.