• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JNI: cannot create multiple jvms within a short time

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's a pity

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

thanks.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic