Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JNI: cannot create multiple jvms within a short time

 
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.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
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.
 
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?
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic