KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > TestWriter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest;
5
6 import com.tc.util.concurrent.ThreadUtil;
7
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10 import java.util.Random JavaDoc;
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 JavaDoc stuff = new HashMap JavaDoc();
20   private Random JavaDoc r = new Random JavaDoc();
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 JavaDoc(stuff.size() + 1), "" + r.nextLong());
33     }
34   }
35
36 }
37
Popular Tags