[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JVM shuts down/starting JVM from another JVM

Posted on 2006-06-19
11
Medium Priority
?
444 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 300 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 300 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 400 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
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 video teaches viewers about errors in exception handling.
Suggested Courses

649 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