• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI: cannot create multiple jvms within a short time  RSS feed

 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try to start 2 jvms through JNI:

first jvm: is for calling java.util.prefs.Preferences to retrieve system settings (classpath,library path of installed java app).

second jvm: calls java app with help of retrieved Preferences (see above).

this does not work. there seems to be problems with creating two virtual machines within a short time, even if i use DestroyJavaVM. both JNI virtual machines are using different variables so there cannot be a variable clash.

if it is not possible to create two jvms within a short time, maybe i should create a jvm only once and call Runtime.exec() with JNI to call my java app?

thanks for your help.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to create a JVM to read settings which you would then use to start another JVM? The settings used to start the first would presumably be defaults, so you're not going to learn anything you didn't already know by doing this, are you?
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my first jvm is retrieving settings with java.util.prefs.Preferences API.
these settings have been set beforehand with a java installer programm, which installed my java GUI application. these settings aren't default values they depend on directories the user choses in a installer wizard.

and i need these settings (java.class.path,library.class.path) to make it possible to start my main java GUI application from a C++ application.
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately you cannot create multiple vms in the same process in JNI, even by doing it sequentially (create exec destroy create exec destroy ...). It's simply not possible.
To achieve what you want you'll have to do it with two sequential processes.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's a pity

will have to use Runtime.exec() to fork a new process then.

thanks.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by manuel aldana:
that's a pity

will have to use Runtime.exec() to fork a new process then.

thanks.



Sounds like it but you can call Runtime.exec from JNI so at least you don't have to leave C++. Still, it sounds to me like you don't need to do that, i.e. start another process. Unless your settings are -X settings, I'm pretty sure you can change the settings at runtime. What settings are you looking to change?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!