82 |
|
final AtomicLong ai = new AtomicLong(1); |
83 |
|
Thread t = new Thread(new Runnable() { |
84 |
|
public void run() { |
85 |
< |
while(!ai.compareAndSet(2, 3)) Thread.yield(); |
85 |
> |
while (!ai.compareAndSet(2, 3)) Thread.yield(); |
86 |
|
}}); |
87 |
|
try { |
88 |
|
t.start(); |
91 |
|
assertFalse(t.isAlive()); |
92 |
|
assertEquals(ai.get(), 3); |
93 |
|
} |
94 |
< |
catch(Exception e) { |
94 |
> |
catch (Exception e) { |
95 |
|
unexpectedException(); |
96 |
|
} |
97 |
|
} |
102 |
|
*/ |
103 |
|
public void testWeakCompareAndSet(){ |
104 |
|
AtomicLong ai = new AtomicLong(1); |
105 |
< |
while(!ai.weakCompareAndSet(1,2)); |
106 |
< |
while(!ai.weakCompareAndSet(2,-4)); |
105 |
> |
while (!ai.weakCompareAndSet(1,2)); |
106 |
> |
while (!ai.weakCompareAndSet(2,-4)); |
107 |
|
assertEquals(-4,ai.get()); |
108 |
< |
while(!ai.weakCompareAndSet(-4,7)); |
108 |
> |
while (!ai.weakCompareAndSet(-4,7)); |
109 |
|
assertEquals(7,ai.get()); |
110 |
|
} |
111 |
|
|
207 |
|
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
208 |
|
AtomicLong r = (AtomicLong) in.readObject(); |
209 |
|
assertEquals(l.get(), r.get()); |
210 |
< |
} catch(Exception e){ |
210 |
> |
} catch (Exception e){ |
211 |
|
unexpectedException(); |
212 |
|
} |
213 |
|
} |