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