1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util;
16  
17  import com.liferay.portal.kernel.util.InitialThreadLocal;
18  
19  import java.util.HashSet;
20  import java.util.Set;
21  
22  /**
23   * <a href="ThirdPartyThreadLocalRegistry.java.html"><b><i>View Source</i></b>
24   * </a>
25   *
26   * <p>
27   * See http://issues.liferay.com/browse/LPS-7864.
28   * </p>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class ThirdPartyThreadLocalRegistry {
33  
34      public static void registerThreadLocal(ThreadLocal<?> threadLocal) {
35          Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
36  
37          threadLocalSet.add(threadLocal);
38      }
39  
40      public static void resetThreadLocals() {
41          Set<ThreadLocal<?>> threadLocalSet = _threadLocalSet.get();
42  
43          if (threadLocalSet == null) {
44              return;
45          }
46  
47          for (ThreadLocal<?> threadLocal : threadLocalSet) {
48              threadLocal.remove();
49          }
50      }
51  
52      private static ThreadLocal<Set<ThreadLocal<?>>> _threadLocalSet =
53          new InitialThreadLocal<Set<ThreadLocal<?>>>(
54              new HashSet<ThreadLocal<?>>());
55  
56  }