Solved

JVM shuts down/starting JVM from another JVM

Posted on 2006-06-19
11
438 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 53
difference of if loops 23 49
jdbc error in jsp application 20 45
arguments to jar 5 26
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

770 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