Solved

JVM shuts down/starting JVM from another JVM

Posted on 2006-06-19
11
439 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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
jsp login check 12 43
String array comparison 4 38
ejb entity bean example 2 17
Crystal Reports Licensing Questions 4 37
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

821 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