[ https://issues.apache.org/jira/browse/GROOVY-8653?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
chenxiaojie updated GROOVY-8653: -------------------------------- Description: {code:java} ConcurrentHashMap<Integer, AtomicInteger> map = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ConcurrentHashMap<Integer, AtomicInteger> map2 = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ConcurrentHashMap<Integer, AtomicInteger> map3 = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ExecutorService es = Executors.newFixedThreadPool(100) 1.upto(10000) { i -> es.execute { AtomicInteger count = map.get(i) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map.putIfAbsent(i, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } for (Integer i = 0; i < 10000; i++) { es.execute { AtomicInteger count = map2.get(i) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map2.putIfAbsent(i, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } for (Integer i = 0; i < 10000; i++) { Integer j = i es.execute { AtomicInteger count = map3.get(j) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map3.putIfAbsent(j, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } es.shutdown() es.awaitTermination(1, TimeUnit.MINUTES) // println 10000 println map.size() {color:red}// println 6583 ??? size is 0-10000 integer println map2.size(){color} // println 10000 println map3.size() {code} was: ConcurrentHashMap<Integer, AtomicInteger> map = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ConcurrentHashMap<Integer, AtomicInteger> map2 = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ConcurrentHashMap<Integer, AtomicInteger> map3 = new ConcurrentHashMap<Integer, AtomicInteger>(10000) ExecutorService es = Executors.newFixedThreadPool(100) 1.upto(10000) { i -> es.execute { AtomicInteger count = map.get(i) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map.putIfAbsent(i, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } for (Integer i = 0; i < 10000; i++) { es.execute { AtomicInteger count = map2.get(i) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map2.putIfAbsent(i, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } for (Integer i = 0; i < 10000; i++) { Integer j = i es.execute { AtomicInteger count = map3.get(j) if (count == null) { count = new AtomicInteger(0) AtomicInteger oldCount = map3.putIfAbsent(j, count) if (oldCount != null) { count = oldCount } } count.incrementAndGet() } } es.shutdown() es.awaitTermination(1, TimeUnit.MINUTES) // println 10000 println map.size() {color:red}// println 6583 ??? size is 0-10000 integer println map2.size(){color} // println 10000 println map3.size() > foreach index value error > ------------------------- > > Key: GROOVY-8653 > URL: https://issues.apache.org/jira/browse/GROOVY-8653 > Project: Groovy > Issue Type: Bug > Components: Groovy Console, groovy-jdk > Affects Versions: 2.3.7, 2.4.15 > Environment: jdk1.7.0_79 > Reporter: chenxiaojie > Priority: Major > Original Estimate: 12h > Remaining Estimate: 12h > > {code:java} > ConcurrentHashMap<Integer, AtomicInteger> map = new > ConcurrentHashMap<Integer, AtomicInteger>(10000) > ConcurrentHashMap<Integer, AtomicInteger> map2 = new > ConcurrentHashMap<Integer, AtomicInteger>(10000) > ConcurrentHashMap<Integer, AtomicInteger> map3 = new > ConcurrentHashMap<Integer, AtomicInteger>(10000) > ExecutorService es = Executors.newFixedThreadPool(100) > 1.upto(10000) { > i -> > es.execute { > AtomicInteger count = map.get(i) > if (count == null) { > count = new AtomicInteger(0) > AtomicInteger oldCount = map.putIfAbsent(i, count) > if (oldCount != null) { > count = oldCount > } > } > count.incrementAndGet() > } > } > for (Integer i = 0; i < 10000; i++) { > es.execute { > AtomicInteger count = map2.get(i) > if (count == null) { > count = new AtomicInteger(0) > AtomicInteger oldCount = map2.putIfAbsent(i, count) > if (oldCount != null) { > count = oldCount > } > } > count.incrementAndGet() > } > } > for (Integer i = 0; i < 10000; i++) { > Integer j = i > es.execute { > AtomicInteger count = map3.get(j) > if (count == null) { > count = new AtomicInteger(0) > AtomicInteger oldCount = map3.putIfAbsent(j, count) > if (oldCount != null) { > count = oldCount > } > } > count.incrementAndGet() > } > } > es.shutdown() > es.awaitTermination(1, TimeUnit.MINUTES) > // println 10000 > println map.size() > {color:red}// println 6583 ??? size is 0-10000 integer > println map2.size(){color} > // println 10000 > println map3.size() > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)