The Artima Developer Community
Sponsored Link

Java Buzz Forum
Friday Java Quiz: What's The Exit Status

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Friday Java Quiz: What's The Exit Status Posted: Jun 18, 2010 10:28 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Friday Java Quiz: What's The Exit Status
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

Most of you probably will read this in Saturday morning. However it's still Friday here, so I'll send this out as a Friday Java Quiz.

The Thread.UncaughtExceptionHandler interface in Java 5 allows Java programs to react to Throwables that are not caught and handled by any method on a thread's call stack.

The following class registers a global uncaught exception handler that is invoked when a Throwable bubbles up to the root of any thread stack:

1    public class Main { 
2        public static void main(String[] args) { 
3            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 
4                public void run() { 
5                    // Clean up resources: close open files, close databases, etc. 
6                } 
7            })); 
8            Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { 
9                public void uncaughtException(Thread t, Throwable e) { 
10                   if (e instanceof Error) { 
11                       System.exit(99); 
12                   } 
13               } 
14           }); 
15           // The application proper: starting the GUI, listening on ServerSockets, etc. 
16       } 
17   } 
18   

Assume a memory leak in the application causes the JVM to run out of memory and the JVM starts to throw OutOfMemoryError that eventually causes line 11 to be executed and the process is terminated soon afterwards.

Q: What will the exit status of the Java process as seen by the shell be? Is it 99? Can it be anything other than 99?

This is a tricky question. The relaxed rule apply: you can use Google, read books or even compile and run test codes.

Read: Friday Java Quiz: What's The Exit Status

Topic: DirecTV to sell local ads for the first time, partners with firm owned by cable rivals Previous Topic   Next Topic Topic: European stocks up as takeover deals offset worries about drop in German investor sentiment

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use