Invoking JavaVM from a Service

P

Paul Woodman

I've got a windows service executable that starts a COM+ application dll
that, when started, calls JNI_CreateJavaVM to invoke the Java Virtual
Machine.
When the machine is logged off though, the COM+ dll stops running.
If i comment out the call to JNI_CreateJavaVM, the COM+ dll remains running
on log out.
Anyone any ideas as to why?Can JavaVM be used in this way, ie does the fact
it's run from a service cause thread issues which would explain this
problem?

Thanks in advance
 
R

Real Gagnon

When the machine is logged off though, the COM+ dll stops running.
If i comment out the call to JNI_CreateJavaVM, the COM+ dll remains
running on log out.

You need to pass the -Xrs (Reduce Signals Xtended-switch) parameter to
the JVM (131 or higher).

From the doc :

<http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.html>

-Xrs
Reduces usage of operating-system signals by the Java virtual machine
(JVM). This option is available beginning with J2SE 1.3.1.

In J2SE 1.3.0, the Shutdown Hooks facility was added to allow orderly
shutdown of a Java application. The intent was to allow user cleanup code
(such as closing database connections) to run at shutdown, even if the
JVM terminates abruptly.

The JVM watches for console control events to implement shutdown
hooks for abnormal JVM termination. Specifically, the JVM registers a
console control handler which begins shutdown-hook processing and returns
TRUE for CTRL_C_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and
CTRL_SHUTDOWN_EVENT.

The JVM uses a similar mechanism to implement the pre-1.2 feature of
dumping thread stacks for debugging purposes. Sun's JVM uses
CTRL_BREAK_EVENT to perform thread dumps.

If the JVM is run as a service (for example, the servlet engine for a
web server), it can receive CTRL_LOGOFF_EVENT but should not initiate
shutdown since the operating system will not actually terminate the
process. To avoid possible interference such as this, the -Xrs command-
line option has been added beginning with J2SE 1.3.1. When the -Xrs
option is used on Sun's JVM, the JVM does not install a console control
handler, implying that it does not watch for or process CTRL_C_EVENT,
CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, or CTRL_SHUTDOWN_EVENT.

There are two consequences of specifying -Xrs:

* Ctrl-Break thread dumps are not available.
* User code is responsible for causing shutdown hooks to run, for
example by calling System.exit() when the JVM is to be terminated.


Bye.
 

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

Forum statistics

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

Latest Threads

Top