271 |
|
} |
272 |
|
} |
273 |
|
|
274 |
– |
static final long COUNTDOWN = 100000; |
275 |
– |
|
274 |
|
class Counter extends CheckedRunnable { |
275 |
|
final AtomicLongArray aa; |
276 |
|
volatile long counts; |
299 |
|
*/ |
300 |
|
public void testCountingInMultipleThreads() throws InterruptedException { |
301 |
|
final AtomicLongArray aa = new AtomicLongArray(SIZE); |
302 |
+ |
long countdown = 10000; |
303 |
|
for (int i = 0; i < SIZE; i++) |
304 |
< |
aa.set(i, COUNTDOWN); |
304 |
> |
aa.set(i, countdown); |
305 |
|
Counter c1 = new Counter(aa); |
306 |
|
Counter c2 = new Counter(aa); |
307 |
|
Thread t1 = new Thread(c1); |
310 |
|
t2.start(); |
311 |
|
t1.join(); |
312 |
|
t2.join(); |
313 |
< |
assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); |
313 |
> |
assertEquals(c1.counts+c2.counts, SIZE * countdown); |
314 |
|
} |
315 |
|
|
316 |
|
/** |
321 |
|
for (int i = 0; i < SIZE; i++) |
322 |
|
x.set(i, -i); |
323 |
|
AtomicLongArray y = serialClone(x); |
324 |
< |
assertTrue(x != y); |
324 |
> |
assertNotSame(x, y); |
325 |
|
assertEquals(x.length(), y.length()); |
326 |
|
for (int i = 0; i < SIZE; i++) { |
327 |
|
assertEquals(x.get(i), y.get(i)); |