123 |
|
* compareAndSet in one thread enables another waiting for value |
124 |
|
* to succeed |
125 |
|
*/ |
126 |
< |
public void testCompareAndSetInMultipleThreads() { |
126 |
> |
public void testCompareAndSetInMultipleThreads() throws Exception { |
127 |
|
x = 1; |
128 |
|
final AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest>a; |
129 |
|
try { |
136 |
|
public void run() { |
137 |
|
while (!a.compareAndSet(AtomicIntegerFieldUpdaterTest.this, 2, 3)) Thread.yield(); |
138 |
|
}}); |
139 |
< |
try { |
140 |
< |
t.start(); |
141 |
< |
assertTrue(a.compareAndSet(this, 1, 2)); |
142 |
< |
t.join(LONG_DELAY_MS); |
143 |
< |
assertFalse(t.isAlive()); |
144 |
< |
assertEquals(a.get(this), 3); |
145 |
< |
} |
146 |
< |
catch (Exception e) { |
147 |
< |
unexpectedException(); |
148 |
< |
} |
139 |
> |
|
140 |
> |
t.start(); |
141 |
> |
assertTrue(a.compareAndSet(this, 1, 2)); |
142 |
> |
t.join(LONG_DELAY_MS); |
143 |
> |
assertFalse(t.isAlive()); |
144 |
> |
assertEquals(a.get(this), 3); |
145 |
|
} |
146 |
|
|
147 |
|
/** |