Code example for ConcurrentMap

Methods: removeputIfAbsent

public class LongRunningServiceInvocationHandler implements RemoteServiceInvocationHandler<LongRunningService> { 
    ConcurrentMap<String, Object> activeClients = new ConcurrentHashMap<String, Object>();
    public Object invoke(ClientContext client, ServiceReference reference, Method method, Object[] args) throws Exception {
        if (activeClients.putIfAbsent(client.getHostIPAddress(), Boolean.TRUE) != null)
            throw new RuntimeException("Only 1 concurrent invocation allowed per client.");
        try { 
            return method.invoke(new LongRunningServiceImpl(), args);
        } finally { 
Connect your IDE to all the code out there  Get Codota for Java