001
014
015 package com.liferay.portal.kernel.util;
016
017 import java.util.HashSet;
018 import java.util.Set;
019
020
024 public class ThreadLocalRegistry {
025
026 public static ThreadLocal<?>[] captureSnapshot() {
027 Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
028
029 return threadLocalSet.toArray(
030 new ThreadLocal<?>[threadLocalSet.size()]);
031 }
032
033 public static void registerThreadLocal(ThreadLocal<?> threadLocal) {
034 Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
035
036 threadLocalSet.add(threadLocal);
037 }
038
039 public static void resetThreadLocals() {
040 Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
041
042 if (threadLocalSet == null) {
043 return;
044 }
045
046 for (ThreadLocal<?> threadLocal : threadLocalSet) {
047 threadLocal.remove();
048 }
049 }
050
051 private static ThreadLocal<Set<ThreadLocal<?>>> _threadLocalSet =
052 new InitialThreadLocal<Set<ThreadLocal<?>>>(
053 ThreadLocalRegistry.class + "._threadLocalSet",
054 new HashSet<ThreadLocal<?>>());
055
056 }