You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "chenxiaojie (JIRA)" <ji...@apache.org> on 2018/06/20 06:30:00 UTC
[jira] [Created] (GROOVY-8653) foreach index value error
chenxiaojie created GROOVY-8653:
-----------------------------------
Summary: 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.4.15, 2.3.7
Environment: jdk1.7.0_79
Reporter: chenxiaojie
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()
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)