Solved

JVM shuts down/starting JVM from another JVM

Posted on 2006-06-19
11
440 Views
Last Modified: 2008-01-09
I have an application which sometimes shuts down the JVM ("HotSpot Virtual Machine Error, Internal Error"). The problem is a known problem and will probably be solved some time in the future.

In this situation I just want to restart the application, but this is not possible using a traditional restart of thread etc., since the JVM is in fact shut down.

Is it possible to run the application through another JVM, which will restart the JVM in case this shuts down?

Which technique would I use to set this up - JNI, and how? An example/solution is very much appreciated.

Regards,
Jesper
0
Comment
Question by:jespersahner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 75 total points
ID: 16934162
You can catch the shut-down of a JVM by using shut-down hook.

http://www.onjava.com/pub/a/onjava/ 2003/03/26/shutdownhook.html

You can use Runtime.exec () to start another java.exe instance from there.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16934170
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 75 total points
ID: 16934448
So, as you can see it should be possible without JNI, UNLESS the JVM is in such a disorder that an exec call
from this shutdown thread is not granted.
Can't you avoid that error by upgrading JAVA? What version do you run?

;JOOP!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jespersahner
ID: 16939982
->mayankeagle: Very interesting technique! I don't know if it will work however, when an internal JVM-error occurs. In this case the JVM writes a log that looks like this:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0117caf3, pid=2688, tid=2740
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)
# Problematic frame:
# J  java.nio.DirectByteBuffer.putInt(JI)Ljava/nio/ByteBuffer;
#
# An error report file with more information is saved as hs_err_pid2688.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

I looks a bit like turning the JVM-power off, so I don't know if your proposal will work, but I will try it out.

Otherwise the Runtime.exec()-solution + waitFor() will solve the problem I guess.

->sciuriware: I am running tha latest JDK 1.5/5.0

The problem is mentioned at:
http://www.jniwrapper.com/pages/forums/forumsThread?threadRootMessage=551
0
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 16940179
Just a thought, you can run a small server programme in the JVM that could be shut down. Then from your application have a socket that connects to this server every few seconds, if it times out then it probably means that the JVM is down. On timeout check the logs (programmatically) and if you find keywords such as "EXCEPTION_ACCESS_VIOLATION" etc then restart the JVM using Runtime.exec().
0
 
LVL 35

Expert Comment

by:girionis
ID: 16940186
> you can run a small server programme in the JVM that could be shut down

Actually this does not need to be a new application, just modify the current application to listen to a specific port via a socket.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16940239
>> when an internal JVM-error occurs

Might still work, the best way is to try it out.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17120735
OK
0
 

Author Comment

by:jespersahner
ID: 17121669
Sorry for the delay..have been very busy doing the half-yearly report at my work :-)

The "shut-down hook"-technique doesn't solve the problem in my case. As I understand it this technique is very similar to catchning uncaught exceptions using Thread.UncaughtExceptionHandler() (new in JDK 1.5/5.0).

In my case I think of the error as a "cold" shut-down whereas a "warm" shut-down may be handled in a proper way.

By the way the problem is not as frequent with the latest JDK 1.6/6.0 Beta-build, but it still occurs from time to time.

Regards,
Jesper
0
 
LVL 35

Expert Comment

by:girionis
ID: 17121892
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 83
ejb mdb examples 1 38
wild fly 8 startup error 2 78
Java ArrayList and if statement 2 55
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question