Exemplo n.º 1
0
 private void add() {
   int i = 0;
   while (i < count) {
     Random rand = new Random();
     int r = rand.nextInt(50);
     if (!hashMap.containsKey(r)) {
       hashMap.put(r, r);
       i++;
     }
   }
 }
Exemplo n.º 2
0
 private void remove() {
   int i = 0;
   while (i < count) {
     Random rand = new Random();
     int r = rand.nextInt(50);
     if (hashMap.containsKey(r)) {
       hashMap.remove(r);
       i++;
     }
   }
 }
Exemplo n.º 3
0
 public void run() {
   if (id % 2 == 0) {
     add();
   } else {
     remove();
   }
   // size should include changes made by other threads
   // (should equal last printed size plus ADD(s) and minus REMOVE(s)
   System.out.println("size: " + hashMap.size());
 }