0N/A/*
2362N/A * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.lang;
0N/Aimport java.lang.ref.*;
0N/A
0N/A/**
0N/A * This class extends <tt>ThreadLocal</tt> to provide inheritance of values
0N/A * from parent thread to child thread: when a child thread is created, the
0N/A * child receives initial values for all inheritable thread-local variables
0N/A * for which the parent has values. Normally the child's values will be
0N/A * identical to the parent's; however, the child's value can be made an
0N/A * arbitrary function of the parent's by overriding the <tt>childValue</tt>
0N/A * method in this class.
0N/A *
0N/A * <p>Inheritable thread-local variables are used in preference to
0N/A * ordinary thread-local variables when the per-thread-attribute being
0N/A * maintained in the variable (e.g., User ID, Transaction ID) must be
0N/A * automatically transmitted to any child threads that are created.
0N/A *
0N/A * @author Josh Bloch and Doug Lea
0N/A * @see ThreadLocal
0N/A * @since 1.2
0N/A */
0N/A
0N/Apublic class InheritableThreadLocal<T> extends ThreadLocal<T> {
0N/A /**
0N/A * Computes the child's initial value for this inheritable thread-local
0N/A * variable as a function of the parent's value at the time the child
0N/A * thread is created. This method is called from within the parent
0N/A * thread before the child is started.
0N/A * <p>
0N/A * This method merely returns its input argument, and should be overridden
0N/A * if a different behavior is desired.
0N/A *
0N/A * @param parentValue the parent thread's value
0N/A * @return the child thread's initial value
0N/A */
0N/A protected T childValue(T parentValue) {
0N/A return parentValue;
0N/A }
0N/A
0N/A /**
0N/A * Get the map associated with a ThreadLocal.
0N/A *
0N/A * @param t the current thread
0N/A */
0N/A ThreadLocalMap getMap(Thread t) {
0N/A return t.inheritableThreadLocals;
0N/A }
0N/A
0N/A /**
0N/A * Create the map associated with a ThreadLocal.
0N/A *
0N/A * @param t the current thread
0N/A * @param firstValue value for the initial entry of the table.
0N/A * @param map the map to store.
0N/A */
0N/A void createMap(Thread t, T firstValue) {
0N/A t.inheritableThreadLocals = new ThreadLocalMap(this, firstValue);
0N/A }
0N/A}