/[classpath]/classpath/java/lang/ThreadLocal.java
ViewVC logotype

Diff of /classpath/java/lang/ThreadLocal.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by ericb, Wed Mar 20 20:04:32 2002 UTC revision 1.4 by mark, Sat Aug 9 18:47:04 2003 UTC
# Line 1  Line 1 
1  /* ThreadLocal -- a variable with a unique value per thread  /* ThreadLocal -- a variable with a unique value per thread
2     Copyright (C) 2000, 2002 Free Software Foundation, Inc.     Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 37  exception statement from your version. * Line 37  exception statement from your version. *
37    
38  package java.lang;  package java.lang;
39    
40    import java.util.Collections;
41  import java.util.Map;  import java.util.Map;
42  import java.util.WeakHashMap;  import java.util.WeakHashMap;
43    
# Line 101  public class ThreadLocal Line 102  public class ThreadLocal
102     * <code>set(Thread, Object)</code> and <code>get(Thread)</code> methods     * <code>set(Thread, Object)</code> and <code>get(Thread)</code> methods
103     * access it. Package visible for use by InheritableThreadLocal.     * access it. Package visible for use by InheritableThreadLocal.
104     */     */
105    final Map valueMap = new WeakHashMap();    final Map valueMap = Collections.synchronizedMap(new WeakHashMap());
106                    
107    /**    /**
108     * Creates a ThreadLocal object without associating any value to it yet.     * Creates a ThreadLocal object without associating any value to it yet.
# Line 135  public class ThreadLocal Line 136  public class ThreadLocal
136    {    {
137      Thread currentThread = Thread.currentThread();      Thread currentThread = Thread.currentThread();
138      // 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
139      // ever modify the returned value.      // ever modify the returned value and valueMap is a synchronizedMap.
140      Object value = valueMap.get(currentThread);      Object value = valueMap.get(currentThread);
141      if (value == null)      if (value == null)
142        {        {
# Line 156  public class ThreadLocal Line 157  public class ThreadLocal
157    public void set(Object value)    public void set(Object value)
158    {    {
159      // 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
160      // ever modify the returned value.      // ever modify the returned value and valueMap is a synchronizedMap.
161      valueMap.put(Thread.currentThread(), value == null ? NULL : value);      valueMap.put(Thread.currentThread(), value == null ? NULL : value);
162    }    }
163  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26