KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > launcher > ExitOnErrorThreadGroup


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.launcher;
18
19 /**
20  * A class that subclasses the {@link ThreadGroup} class. This class is used
21  * by {@link ChildMain#main(String[])} to run the target application. By using
22  * this class, any {@link Error} other than {@link ThreadDeath} thrown by
23  * threads created by the target application will be caught the process
24  * terminated. By default, the JVM will only print a stack trace of the
25  * {@link Error} and destroy the thread. However, when an uncaught
26  * {@link Error} occurs, it normally means that the JVM has encountered a
27  * severe problem. Hence, an orderly shutdown is a reasonable approach.
28  * <p>
29  * Note: not all threads created by the target application are guaranteed to
30  * use this class. Target application's may bypass this class by creating a
31  * thread using the {@link Thread#Thread(ThreadGroup, String)} or other similar
32  * constructors.
33  *
34  * @author Patrick Luby
35  */

36 public class ExitOnErrorThreadGroup extends ThreadGroup JavaDoc {
37
38     //------------------------------------------------------------ Constructors
39

40     /**
41      * Constructs a new thread group. The parent of this new group is the
42      * thread group of the currently running thread.
43      *
44      * @param name the name of the new thread group
45      */

46     public ExitOnErrorThreadGroup(String JavaDoc name) {
47
48         super(name);
49
50     }
51
52     //----------------------------------------------------------------- Methods
53

54     /**
55      * Trap any uncaught {@link Error} other than {@link ThreadDeath} and exit.
56      *
57      * @param t the thread that is about to exit
58      * @param e the uncaught exception
59      */

60     public void uncaughtException(Thread JavaDoc t, Throwable JavaDoc e) {
61
62         if (e instanceof ThreadDeath JavaDoc)
63             return;
64
65         Launcher.error(e);
66         System.exit(1);
67
68     }
69
70 }
71
Popular Tags