KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > ExecutionContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise;
24
25 import java.lang.InheritableThreadLocal JavaDoc;
26 import java.util.Hashtable JavaDoc;
27
28 /**
29  * This class that implements ExecutionContext that gets
30  * stored in Thread Local Storage. If the current thread creates
31  * child threads, the context info that is stored in the current
32  * thread is automatically propogated to the child threads.
33  *
34  * Two class methods serve as a convinient way to set/get the
35  * Context information within the current thread.
36  *
37  * Thread Local Storage is a concept introduced in JDK1.2. So, it
38  * will not work on earlier releases of JDK.
39  *
40  * @see java.lang.ThreadLocal
41  * @see java.lang.InheritableThreadLocal
42  *
43  */

44 public class ExecutionContext {
45     private static InheritableThreadLocal JavaDoc current= new InheritableThreadLocal JavaDoc();
46
47     /**
48      * This method can be used to add a new hashtable for storing the
49      * Thread specific context information. This method is useful to add a
50      * deserialized Context information that arrived over the wire.
51      * @param A hashtable that stores the current thread's context
52      * information.
53      */

54     public static void setContext(Hashtable JavaDoc ctxTable) {
55     if (ctxTable != null) {
56         current.set(ctxTable);
57     } else {
58         current.set(new Hashtable JavaDoc());
59     }
60     }
61
62     /**
63      * This method returns the hashtable that stores the thread specific
64      * Context information.
65      * @return The Context object stored in the current TLS. It always
66      * returns a non null value;
67      */

68     public static Hashtable JavaDoc getContext() {
69      if (current.get() == null) {
70          setContext(null); // Create a new one...
71
}
72      return (Hashtable JavaDoc) current.get();
73     }
74 }
75
76
77
78
79
80
Popular Tags