1 |
/* InheritableThreadLocal -- a ThreadLocal which inherits values across threads |
/* InheritableThreadLocal -- a ThreadLocal which inherits values across threads |
2 |
Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
37 |
|
|
38 |
package java.lang; |
package java.lang; |
39 |
|
|
40 |
|
import java.util.ArrayList; |
41 |
|
import java.util.Collections; |
42 |
import java.util.Iterator; |
import java.util.Iterator; |
43 |
import java.util.List; |
import java.util.List; |
44 |
import java.util.ArrayList; |
import java.util.Map; |
45 |
import java.util.WeakHashMap; |
import java.util.WeakHashMap; |
46 |
|
|
47 |
/** |
/** |
69 |
* List can be collected, too. Maps to a list in case the user overrides |
* List can be collected, too. Maps to a list in case the user overrides |
70 |
* equals. |
* equals. |
71 |
*/ |
*/ |
72 |
private static final WeakHashMap threadMap = new WeakHashMap(); |
private static final Map threadMap |
73 |
|
= Collections.synchronizedMap(new WeakHashMap()); |
74 |
|
|
75 |
/** |
/** |
76 |
* Creates a new InheritableThreadLocal that has no values associated |
* Creates a new InheritableThreadLocal that has no values associated |
80 |
{ |
{ |
81 |
Thread currentThread = Thread.currentThread(); |
Thread currentThread = Thread.currentThread(); |
82 |
// Note that we don't have to synchronize, as only this thread will |
// Note that we don't have to synchronize, as only this thread will |
83 |
// ever modify the returned heritage. |
// ever modify the returned heritage and threadMap is a synchronizedMap. |
84 |
List heritage = (List) threadMap.get(currentThread); |
List heritage = (List) threadMap.get(currentThread); |
85 |
if (heritage == null) |
if (heritage == null) |
86 |
{ |
{ |
117 |
// The currentThread is the parent of the new thread. |
// The currentThread is the parent of the new thread. |
118 |
Thread parentThread = Thread.currentThread(); |
Thread parentThread = Thread.currentThread(); |
119 |
// Note that we don't have to synchronize, as only this thread will |
// Note that we don't have to synchronize, as only this thread will |
120 |
// ever modify the returned heritage. |
// ever modify the returned heritage and threadMap is a synchronizedMap. |
121 |
ArrayList heritage = (ArrayList) threadMap.get(parentThread); |
ArrayList heritage = (ArrayList) threadMap.get(parentThread); |
122 |
if (heritage != null) |
if (heritage != null) |
123 |
{ |
{ |