DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=38986>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=38986 ------- Additional Comments From [EMAIL PROTECTED] 2006-03-16 16:26 ------- Well System.out.println synchronizes writing to systems output stream but not put and get methods that were outside of System.out.println method call. Anyway, may be code below will help. Instead of writing to System.out each thread has its own Baffer to collect test results. Writer starts reader thread after 10th Map entry, just to make sure that reader has something to read Main thread sleeps for 10 seconds and displays results. You can also try it without any writing to console. After all - all what we looking for in this case is ConcurrentModificationException. -Regards import java.util.HashMap; import java.util.Map; import java.util.Set; public class SynchronizeDemo { public static Map actions = new HashMap(); public static StringBuffer readOut = new StringBuffer(); public static StringBuffer writeOut = new StringBuffer(); public static void main(String[] args) throws InterruptedException { SynchronizeDemo demo = new SynchronizeDemo(); demo.test(); Thread.sleep(10000); System.out.println("Result: " + writeOut.toString() + readOut.toString()); } public void test() throws InterruptedException{ MapWriter writer = new MapWriter(); writer.start(); } public class MapReader extends Thread{ public void run(){ for(int i = 0; i<250; i++){// read Map 250 times Set keys = actions.keySet(); readOut.append("\n" + this.getClass ().getName()); for(int ii = 0; ii < keys.size(); ii++) {// display all actions from the map readOut.append(" ['_action_key_" + ii + "' mapped to '" + actions.get("_action_key_" + ii) +"']"); } } } } public class MapWriter extends Thread{ public void run(){ synchronized(SynchronizeDemo.actions){ for(int i = 0; i<250; i++){// put new action 250 times if(i==10){ MapReader reader = new MapReader(); reader.start(); } actions.put("_action_key_" + i, "_action_class_" + i); writeOut.append("\n" + this.getClass().getName() + "'_action_key_" + i + "' '_action_class_" + i + "'"); } } } } } -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]