Java, jni.h and native method

B

bigbinc

What is good practice for writing a server with C/C++ that uses java.

Should I have instantiate the Java when the server launches or should
I call the virtual machine when I receive requests that use the java
code and then shutdown immediately.

The best approach would use launch the jvm at the start of the server,
but if the server will be on for days, I dont know what will happen to
the jvm if it is up for that long.
 
G

Gordon Beaton

What is good practice for writing a server with C/C++ that uses
java.

Make up your mind: do you mean C or C++?
Should I have instantiate the Java when the server launches or
should I call the virtual machine when I receive requests that use
the java code and then shutdown immediately.

Your subject line implies the opposite relationship, but I'll assume
you're talking about using the invocation API to embed a JVM into your
C application so that you can call Java methods from C. If that's not
the case, be more clear about what you plan to do.

You can't stop and restart the embedded JVM. I believe there are
problems with DestroyJavaVM() that prevent it from shutting down
properly (and from starting ever again). The documentation for
DestroyJavaVM() says "does not support unloading the VM". That leaves
you no choice but to maintain the JVM you initially started.
The best approach would use launch the jvm at the start of the
server, but if the server will be on for days, I dont know what will
happen to the jvm if it is up for that long.

I guess you'll find out. If you're worried about it then you can
restart your server occasionally, or use an external helper to embed
the JVM instead (so that you can stop and restart the helper).

Or you could just run a JVM in the "normal" way in a separate process,
and send it requests from the C server using a Socket or other
mechanism.

/gordon
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top