1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
– |
import java.util.concurrent.Semaphore; |
10 |
|
|
11 |
|
public class ThreadLocalTest extends JSR166TestCase { |
12 |
|
public static void main(String[] args) { |
38 |
|
* remove causes next access to return initial value |
39 |
|
*/ |
40 |
|
public void testRemove() { |
41 |
< |
assertEquals(tl.get(), one); |
41 |
> |
assertSame(tl.get(), one); |
42 |
|
tl.set(two); |
43 |
< |
assertEquals(tl.get(), two); |
43 |
> |
assertSame(tl.get(), two); |
44 |
|
tl.remove(); |
45 |
< |
assertEquals(tl.get(), one); |
45 |
> |
assertSame(tl.get(), one); |
46 |
|
} |
47 |
|
|
48 |
|
/** |
50 |
|
* initial value |
51 |
|
*/ |
52 |
|
public void testRemoveITL() { |
53 |
< |
assertEquals(itl.get(), zero); |
53 |
> |
assertSame(itl.get(), zero); |
54 |
|
itl.set(two); |
55 |
< |
assertEquals(itl.get(), two); |
55 |
> |
assertSame(itl.get(), two); |
56 |
|
itl.remove(); |
57 |
< |
assertEquals(itl.get(), zero); |
57 |
> |
assertSame(itl.get(), zero); |
58 |
|
} |
59 |
|
|
60 |
|
private class ITLThread extends Thread { |
66 |
|
child = new ITLThread(x); |
67 |
|
child.start(); |
68 |
|
} |
69 |
< |
Thread.currentThread().yield(); |
69 |
> |
Thread.yield(); |
70 |
|
|
71 |
|
int threadId = itl.get().intValue(); |
72 |
|
for (int j = 0; j < threadId; j++) { |
73 |
|
x[threadId]++; |
74 |
< |
Thread.currentThread().yield(); |
74 |
> |
Thread.yield(); |
75 |
|
} |
76 |
|
|
77 |
|
if (child != null) { // Wait for child (if any) |