1 4 package com.tctest; 5 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.Map ; 9 10 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 if (stuff.size() > 0 && (stuff.size() % 4) == 0) { 40 for (Iterator i = stuff.values().iterator(); i.hasNext();) { 41 i.next(); 42 } 43 } 44 } 45 } 47 48 protected String getName() { 49 return name; 50 } 51 52 } 53 | Popular Tags |