01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest;
05:
06: import com.tc.util.concurrent.ThreadUtil;
07:
08: import java.util.HashMap;
09: import java.util.Map;
10: import java.util.Random;
11:
12: /**
13: * writer for the FastReadSlowWriteTest
14: */
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: }
|