Urgent Help: Multiple calls to JNI_CreateJavaVM

M

muhammad.hamdan

Hello,

I have 2 VC++ codes calling Java functions. An application loads these
VC++ dll files. When the application invokes the first VC++ dll , I
initialize and create the JVM using the JNI_CreateJavaVM(&jvm, (void**)
&env,&vm_args) funtion. This works fine and am able to perform all the
operations.
I destroy the JVM when the application is closed.

The problem arises when the application tries to load my other VC++
dll. The second initialise which also has a JNI_CreateJavaVM(&jvm,
(void**) &env,&vm_args) function fails as this returns a -1.

Is there anyway I can have both my dll functioning at the same time?

The thought of destroying JVM after every operation and not leaving it
open till the application closes crossed my mind, even though
performance will be an issue, but that also wouldnt solve the problem
because the application is multi-threaded. So when the first code is
being executed, if someone calls the second one it will fail because
the init fails. Also since it is a known bug that we cannot destroy and
create a VM in the same process, am not able to do that.

Say I make the JNI_CreateJavaVM() in the first dll and I always make
sure that this is initialized first, is there anyway I can do a
(jvm)->AttachThread() to the first one that gets created? and also get
the JNIenv * value from that dll?

Any help would be appreciated. Thanks

Ham
 
V

Victor Bazarov

I have 2 VC++ codes calling Java functions. An application loads these
VC++ dll files. When the application invokes the first VC++ dll , [...]

The problem arises when the application tries to load my other VC++
dll. [...]

Is there anyway I can have both my dll functioning at the same time?
[...]

This is not the right place to post your platform-specific question.
Please read the FAQ 5.9 for suggestions which newsgroups are more
appropriate.

V
 
R

Roland Pibinger

I have 2 VC++ codes calling Java functions. An application loads these
VC++ dll files. When the application invokes the first VC++ dll , I
initialize and create the JVM using the JNI_CreateJavaVM(&jvm, (void**)
&env,&vm_args) funtion. This works fine and am able to perform all the
operations. I destroy the JVM when the application is closed.

The problem arises when the application tries to load my other VC++
dll. The second initialise which also has a JNI_CreateJavaVM(&jvm,
(void**) &env,&vm_args) function fails as this returns a -1.

Is there anyway I can have both my dll functioning at the same time?

Your question is very specific and platform dependent. The gerneral
question is: How do you initialize something once and only once? The
usual answer: Use a Singleton.

Best wishes,
Roland Pibinger
 

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
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top