Solved

JVM shuts down/starting JVM from another JVM

Posted on 2006-06-19
11
436 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:mayankeagle
mayankeagle 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:mayankeagle
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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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:mayankeagle
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now