ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/MapLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/MapLoops.java (file contents):
Revision 1.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.3 by dl, Mon Feb 19 00:46:06 2007 UTC

# Line 1 | Line 1
1 /*
2 * @test
3 * @synopsis Exercise multithreaded maps, by default
4 * ConcurrentHashMap.  Each thread does a random walk though elements
5 * of "key" array. On each iteration, it checks if table includes key.
6 * If absent, with probablility pinsert it inserts it, and if present,
7 * with probablility premove it removes it.  (pinsert and premove are
8 * expressed as percentages to simplify parsing from command line.)
9 */
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3 < * Expert Group and released to the public domain. Use, modify, and
4 < * redistribute this code in any way without acknowledgement.
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5   */
6  
16
7   import java.util.*;
8   import java.util.concurrent.*;
9  
10   public class MapLoops {
11 <    static int nkeys       = 10000;
11 >    static int nkeys       = 1000;
12      static int pinsert     = 60;
13      static int premove     = 2;
14      static int maxThreads  = 100;
15 <    static int nops        = 8000000;
15 >    static int nops        = 1000000;
16      static int removesPerMaxRandom;
17      static int insertsPerMaxRandom;
18  
# Line 114 | Line 104 | public class MapLoops {
104          // Uncomment to start with a non-empty table
105          //        for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
106          //            map.put(key[j], key[j]);
107 +        shuffleKeys(key);
108          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
109          CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
110          for (int t = 0; t < i; ++t)
111 <            pool.execute(new Runner(map, key, barrier));
111 >            pool.execute(new Runner(t, map, key, barrier));
112          barrier.await();
113          barrier.await();
114          long time = timer.getTime();
# Line 131 | Line 122 | public class MapLoops {
122      static class Runner implements Runnable {
123          final Map<Integer,Integer> map;
124          final Integer[] key;
125 <        final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
125 >        final LoopHelpers.SimpleRandom rng;
126          final CyclicBarrier barrier;
127          int position;
128          int total;
129  
130 <        Runner(Map<Integer,Integer> map, Integer[] key,  CyclicBarrier barrier) {
130 >        Runner(int id, Map<Integer,Integer> map, Integer[] key,  CyclicBarrier barrier) {
131              this.map = map;
132              this.key = key;
133              this.barrier = barrier;
134 <            position = key.length / 2;
134 >            position = key.length / 2;
135 >            rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L);
136 >            rng.next();
137          }
138  
139          int step() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines