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 java.util.HashMap;
07: import java.util.Iterator;
08: import java.util.Map;
09:
10: /**
11: * Reads from the shared map and that's it
12: */
13: public class TestReader {
14:
15: public final static int READ_COUNT = 2000;
16:
17: private Map stuff = new HashMap();
18: private String name;
19:
20: public TestReader(String name) {
21: this .name = name;
22: }
23:
24: public void read() {
25: try {
26: int count = 0;
27: while (count++ < READ_COUNT) {
28: doARead();
29: }
30: } catch (StackOverflowError e) {
31: e.printStackTrace(System.out);
32: throw e;
33: }
34: }
35:
36: public void doARead() {
37: synchronized (stuff) {
38: // System.out.println("begin Reading:" + name);
39: if (stuff.size() > 0 && (stuff.size() % 4) == 0) {
40: for (Iterator i = stuff.values().iterator(); i
41: .hasNext();) {
42: i.next();
43: }
44: }
45: }
46: // System.out.println("DONE Reading:" + name);
47: }
48:
49: protected String getName() {
50: return name;
51: }
52:
53: }
|