Results 1 to 8 of 8
  1. #1
    guest_user is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default How can I restart my jvm and program programmatically?

    if i catch an exception and I want to restart my program from the first statement in main, how would I go about doing that?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default

    Are you asking about how to loop back to the first instruction?
    If you want to exit a JVM and start a new JVM that is a bit tricky. There would need to be another program outside of the JVM that would get control while your original JVM exits and then this other program would start a new JVM with your program again later.
    What is the problem you are trying to solve?

  3. #3
    guest_user is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are you asking about how to loop back to the first instruction?
    If you want to exit a JVM and start a new JVM that is a bit tricky. There would need to be another program outside of the JVM that would get control while your original JVM exits and then this other program would start a new JVM with your program again later.
    What is the problem you are trying to solve?
    I have 2 machines, A and B both have windows services which invoke my java program via JNI. At any point, only one instance of the program is running and the other acts as a failover mechanism, i.e. when A fails perhaps due to a hardware fault, machine B takes would detect this and start up its instance of the java program.

    Problem is that when B starts up its instance of the java program, it would start it at the statement where A originally crashed, not at the beginning and as a result, some variables are not initialized properly as there is no way of transferring the state from A to B. What I would like to do is to reinitialize the JVM on machine B such that it starts all over again at the beginning with the correct env variables as if I had just invoked the program from scratch.

    I can't create a new process through process builder as this would sever the link between the new process and windows services. Any ideas?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default

    Problem is that when B starts up its instance of the java program, it would start it at the statement where A originally crashed, not at the beginning
    How does B know where A "crashed"? How does it skip over the initialization code to get to that point?
    How do the two PCs communicated?

    What I would like to do is to reinitialize the JVM on machine B such that it starts all over again at the beginning
    Can your code be run from a batch file that has a loop? When a program wants to "restart" it exits and the batch file loops and restarts the program.

  5. #5
    guest_user is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    How does B know where A "crashed"? How does it skip over the initialization code to get to that point?
    How do the two PCs communicated?


    Can your code be run from a batch file that has a loop? When a program wants to "restart" it exits and the batch file loops and restarts the program.
    A and B are on a cluster and communicate via hyper v, all the crash detection, etc is done by hyper v

    it'll be best if the java program can reinitialize itself

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default

    best if the java program can reinitialize itself
    Is the program told it should reinitialize itself?
    Then it should be rewritten to do that when it is directed to.

    What is the program doing while it is waiting for its turn to take over?
    Is it sleeping or looping?
    What if no initialization is done until it gets the message it is to take over.

  7. #7
    guest_user is offline Member
    Join Date
    May 2011
    Posts
    47
    Rep Power
    0

    Default

    the program is a windows service in the stop state when it is not running, when the program on the other side crashes, the program is started at the exact same statement before the crash on the other side

    is there a way to reinitialize the jvm and make it run from the first statement instead?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default

    a way to reinitialize the jvm and make it run from the first statement instead
    This sounds like it is mostly about using a feature of the OS.

    What program starts the stopped program? Can the stopped program detect that it has been stopped?
    Can the stopped program be stopped at the point that you want it to start from?

Similar Threads

  1. Programmatically starting cell editing in JTable
    By javaexplorer in forum AWT / Swing
    Replies: 2
    Last Post: 05-21-2010, 05:33 PM
  2. Replies: 0
    Last Post: 05-19-2010, 10:44 PM
  3. Replies: 0
    Last Post: 05-13-2010, 08:03 PM
  4. Replies: 6
    Last Post: 11-04-2009, 10:41 PM
  5. Close a JDialog Programmatically
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 07-06-2007, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •