Java app dies on logoff

D

David Jenkins

Dear Java experts,

I've written a small Java 1.3.1 application running on Windows2000 server,
that connects to an Oracle database (9i) and to MQSeries (5.3), and passes
information between them. I installed it as a Windows service, trying both
the generic 'srvany' service utility supplied by Microsoft, and then using a
custom 'C' application that launches the JVM and invokes the Java app's
'main' method. In both cases, my app runs fine as a service, but dies on
logoff, regardless of whether it is installed under the Windows 'System'
account, or a local machine account, or a network account. I also tried
invoking it as an MQSeries custom service--it launches as part of the MQ
environment, and runs fine until I log off. (MQ and Oracle continue to run
when logged off.)

Can anyone suggest a reason why my app won't run in a logged-off state?
This is driving me nuts, so any and all help will be very much appreciated.

David Jenkins
(e-mail address removed)
 
S

Stian Bakken

The vm will by default terminate when logoff is performed. You must register
a custom logoff handler with the process. Try the following in your JNI
service application:

SetConsoleCtrlHandler(logoffHandler, TRUE);
..
..
BOOL WINAPI logoffHandler(DWORD dwCtrlType)
{
switch(dwCtrlType)
{
case CTRL_C_EVENT:
return TRUE;
case CTRL_CLOSE_EVENT:
return TRUE;
case CTRL_SHUTDOWN_EVENT:
// You may want to do some things in your java app here
return TRUE;
case CTRL_LOGOFF_EVENT:
return TRUE;
}
return FALSE;
}


Best of luck! :)
Stian
 
M

Manfred Rosenboom

Stian said:
The vm will by default terminate when logoff is performed. You must register
a custom logoff handler with the process.

Much simpler you can start the JVM with the parameter -Xrs to ignore this
signal/event.

Best,
Manfred
 
D

David Jenkins

Thanks, Manfred & Stian. I should have mentioned that my custom 'C' routine
did include a logoff handler, virtually identical to the code Stian offered.
(I also have to confess, I got the 'C' program from a very nice person named
Bill Giel, who posted it on http://www.kcmultimedia.com/javaserv/.) I will
try adding the -Xrs parameter on startup & crossing my fingers.

I'm very grateful for your help! Half the office is scratching their heads
over this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top