< prev index next >

src/java.base/share/classes/jdk/internal/misc/TerminatingThreadLocal.java

Print this page

 62     // called from the corresponding code int Thread/ThreadLocal class.
 63 
 64     /**
 65      * Invokes the TerminatingThreadLocal's {@link #threadTerminated()} method
 66      * on all instances registered in current thread.
 67      */
 68     public static void threadTerminated() {
 69         for (TerminatingThreadLocal<?> ttl : REGISTRY.get()) {
 70             ttl._threadTerminated();
 71         }
 72     }
 73 
 74     private void _threadTerminated() { threadTerminated(get()); }
 75 
 76     /**
 77      * Register given TerminatingThreadLocal
 78      *
 79      * @param tl the ThreadLocal to register
 80      */
 81     public static void register(TerminatingThreadLocal<?> tl) {
 82         REGISTRY.get().add(tl);

 83     }
 84 
 85     /**
 86      * Unregister given TerminatingThreadLocal
 87      *
 88      * @param tl the ThreadLocal to unregister
 89      */
 90     private static void unregister(TerminatingThreadLocal<?> tl) {
 91         REGISTRY.get().remove(tl);

 92     }
 93 
 94     /**
 95      * a per-thread registry of TerminatingThreadLocal(s) that have been registered
 96      * but later not unregistered in a particular thread.
 97      */
 98     public static final ThreadLocal<Collection<TerminatingThreadLocal<?>>> REGISTRY =
 99         new ThreadLocal<>() {
100             @Override
101             protected Collection<TerminatingThreadLocal<?>> initialValue() {
102                 return Collections.newSetFromMap(new IdentityHashMap<>(4));
103             }
104         };
105 }

 62     // called from the corresponding code int Thread/ThreadLocal class.
 63 
 64     /**
 65      * Invokes the TerminatingThreadLocal's {@link #threadTerminated()} method
 66      * on all instances registered in current thread.
 67      */
 68     public static void threadTerminated() {
 69         for (TerminatingThreadLocal<?> ttl : REGISTRY.get()) {
 70             ttl._threadTerminated();
 71         }
 72     }
 73 
 74     private void _threadTerminated() { threadTerminated(get()); }
 75 
 76     /**
 77      * Register given TerminatingThreadLocal
 78      *
 79      * @param tl the ThreadLocal to register
 80      */
 81     public static void register(TerminatingThreadLocal<?> tl) {
 82         if (!Thread.currentThread().isVirtual())
 83             REGISTRY.get().add(tl);
 84     }
 85 
 86     /**
 87      * Unregister given TerminatingThreadLocal
 88      *
 89      * @param tl the ThreadLocal to unregister
 90      */
 91     private static void unregister(TerminatingThreadLocal<?> tl) {
 92         if (!Thread.currentThread().isVirtual())
 93             REGISTRY.get().remove(tl);
 94     }
 95 
 96     /**
 97      * a per-thread registry of TerminatingThreadLocal(s) that have been registered
 98      * but later not unregistered in a particular thread.
 99      */
100     public static final ThreadLocal<Collection<TerminatingThreadLocal<?>>> REGISTRY =
101         new ThreadLocal<>() {
102             @Override
103             protected Collection<TerminatingThreadLocal<?>> initialValue() {
104                 return Collections.newSetFromMap(new IdentityHashMap<>(4));
105             }
106         };
107 }
< prev index next >