@@ -0,0 +1,2307 @@
+//  Copyright 2016 The Minorminor Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A%0Apackage jdktest;%0A%0Aimport java.util.Map;%0Aimport java.util.concurrent.ConcurrentHashMap;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.atomic.AtomicLong;%0A%0Apublic class ConcurrentHashMapTest %7B%0A    private Map%3CString, AtomicLong%3E accounts = new ConcurrentHashMap();%0A%0A    public ConcurrentHashMapTest() %7B%0A        accounts.put(%22account1%22, new AtomicLong(0l));%0A        accounts.put(%22account2%22, new AtomicLong(0l));%0A        accounts.put(%22account3%22, new AtomicLong(0l));%0A    %7D%0A%0A    public void increaseIt() %7B%0A        for (int i = 0; i %3C 50; i++) %7B%0A            for (String acount : accounts.keySet()) %7B%0A                //accounts.get(acount).getAndIncrement();%0A                accounts.put(acount, new AtomicLong(accounts.get(acount).longValue()+1));%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void test() %7B%0A        ExecutorService tpool = Executors.newFixedThreadPool(2);%0A        tpool.submit(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                increaseIt();%0A            %7D%0A        %7D);%0A        tpool.submit(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                increaseIt();%0A            %7D%0A        %7D);%0A        try %7B%0A            tpool.awaitTermination(1, TimeUnit.SECONDS);%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        tpool.shutdown();%0A        System.out.println(accounts);%0A%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        int i = 0;%0A        while (i %3C 10) %7B%0A            new ConcurrentHashMapTest().test();%0A            i++;%0A        %7D%0A    %7D%0A%7D%0A

Test ConcurrentHashMap