< prev index next >

src/java.base/share/classes/java/lang/ThreadLocal.java

Print this page

        

@@ -157,21 +157,32 @@
      * by an invocation of the {@link #initialValue} method.
      *
      * @return the current thread's value of this thread-local
      */
     public T get() {
-        Thread t = Thread.currentThread();
+        return get(Thread.currentThread());
+    }
+
+    /**
+     * Returns the value in the current kernel thread's copy of this
+     * thread-local variable.
+     */
+    T getCarrierThreadLocal() {
+        return get(Thread.currentCarrierThread());
+    }
+
+    private T get(Thread t) {
         ThreadLocalMap map = getMap(t);
         if (map != null) {
             ThreadLocalMap.Entry e = map.getEntry(this);
             if (e != null) {
                 @SuppressWarnings("unchecked")
                 T result = (T)e.value;
                 return result;
             }
         }
-        return setInitialValue();
+        return setInitialValue(t);
     }
 
     /**
      * Returns {@code true} if there is a value in the current thread's copy of
      * this thread-local variable, even if that values is {@code null}.

@@ -189,13 +200,12 @@
      * Variant of set() to establish initialValue. Used instead
      * of set() in case user has overridden the set() method.
      *
      * @return the initial value
      */
-    private T setInitialValue() {
+    private T setInitialValue(Thread t) {
         T value = initialValue();
-        Thread t = Thread.currentThread();
         ThreadLocalMap map = getMap(t);
         if (map != null) {
             map.set(this, value);
         } else {
             createMap(t, value);
< prev index next >