jni problem - destroy jvm and rebuild it

Discussion in 'Java' started by Bert Boehne, Oct 5, 2006.

  1. Bert Boehne

    Bert Boehne Guest

    hi!
    i'm busy with jni. i want to start a jvm from my c++ code and call a
    java method. that's working so far. but i have the problem that it has
    to be possible to destroy the jvm and create afterwards again. i can't
    just create the jvm in the main program and let it run until the main
    program ends. that's because i'm writing a plug in to an existing program...
    i downloaded the source from sun where i found the file jni.cpp. there
    are the functions JNI_CreateJavaVM, jni_DestroyJavaVM and so on. also
    there is a global variable:

    volatile jint num_vm_created = 0; // number of VMs created so far

    this variable will be checked at a call of JNI_CreateJavaVM. would it be
    possible to set this variable to zero after calling jni_DestroyVM
    (jni_DestroyJavaVM doesn't do that)i could create a jvm again.

    now, here is my question: does someone know how to reach that variable
    to set it to 0 again? or does someone have another idea to do the job?

    greats,

    bert
     
    Bert Boehne, Oct 5, 2006
    #1
    1. Advertising

  2. Bert Boehne

    Chris Uppal Guest

    Bert Boehne wrote:

    > i'm busy with jni. i want to start a jvm from my c++ code and call a
    > java method. that's working so far. but i have the problem that it has
    > to be possible to destroy the jvm and create afterwards again.


    Then, I'm afraid, you are out of luck. It can't be done. (And yes, I agree
    that sucks.)


    > now, here is my question: does someone know how to reach that variable
    > to set it to 0 again? or does someone have another idea to do the job?


    First you should find /why/ Sun have that variable, and work out how to fix
    whatever technical problem it is that the variable is protecting against.

    -- chris
     
    Chris Uppal, Oct 5, 2006
    #2
    1. Advertising

  3. Hi Bert,

    At least up to JDK 1.4.2 this isn't possible!
    You have in all JDK versions the function jni_DestroyVM, but you can't
    create a new instance of the JVM in the same process after calling this
    function :-((

    If my memory serves me well, this should be possible with the
    Java 5 JVM, but I haven't give it a try and, to be honest,
    I doubt that it is really working in Java 5 until I have seen
    it working on my machine ;-)

    Best,
    Manfred
     
    Manfred Rosenboom, Oct 5, 2006
    #3
  4. Bert Boehne

    Bert Boehne Guest

    hi Manfred!

    i'm using jdk 1.5.0_07. so i think it's still not fixed. :(
    i think there will be a very big party when this becomes possible!

    greats,

    bert
     
    Bert Boehne, Oct 5, 2006
    #4
  5. Bert Boehne

    Chris Uppal Guest

    Manfred Rosenboom wrote:

    > If my memory serves me well, this should be possible with the
    > Java 5 JVM, but I haven't give it a try and, to be honest,
    > I doubt that it is really working in Java 5 until I have seen
    > it working on my machine ;-)


    Just tried it with 1.5, and it still fails.

    If this is something that they are thinking of fixing, then that is excellent
    news -- but like you, I'll believe it only when I see it (if then).

    -- chris
     
    Chris Uppal, Oct 5, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Hooke

    Re: Handling both MS JVM and Sun JVM

    Kevin Hooke, Aug 26, 2003, in forum: Java
    Replies:
    2
    Views:
    899
  2. Lasse
    Replies:
    1
    Views:
    719
    Jon A. Cruz
    Jan 5, 2004
  3. Young-Jin Lee

    MS JVM and Sun JVM problem

    Young-Jin Lee, Jan 20, 2004, in forum: Java
    Replies:
    3
    Views:
    592
    Mickey Segal
    Jan 21, 2004
  4. davidb
    Replies:
    2
    Views:
    1,062
    davidb
    Aug 30, 2006
  5. Ook
    Replies:
    2
    Views:
    352
Loading...

Share This Page