1 4 package com.tctest; 5 6 import com.tc.util.concurrent.ThreadUtil; 7 8 import java.util.HashMap ; 9 import java.util.Map ; 10 import java.util.Random ; 11 12 15 public class TestWriter { 16 public final static int WRITE_COUNT = 100; 17 public final static int WRITE_DELAY = 10; 18 19 private Map stuff = new HashMap (); 20 private Random r = new Random (); 21 22 public void write() { 23 int count = 0; 24 while (count++ < WRITE_COUNT) { 25 doAWrite(); 26 ThreadUtil.reallySleep(WRITE_DELAY); 27 } 28 } 29 30 public void doAWrite() { 31 synchronized (stuff) { 32 stuff.put(new Integer (stuff.size() + 1), "" + r.nextLong()); 33 } 34 } 35 36 } 37 | Popular Tags |