Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - class Sln {
- AtomicInteger globalCounter = new AtomicInterger();
- Map<String, Integer> counterPerKey = new ConcurrentHashMap<>()
- class Holder{
- Integer value
- }
- public Holder doWorkMultipleThreads(String key) {
- if (total.get() < 1000) {
- Integer newTotal = counterPerKey.merge(key, 1, Integer::sum);
- globalCounter.increment();
- return new Holder(newTotal);
- }
- }
- }
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment                    
                 
                    