Code example for ConcurrentHashMap

Methods: containsKey, get, putIfAbsent

0
     * @param wsdlLocation The location of the WSDL 
     * @return A registry instance running on the specified location 
     */ 
    public static ServiceRegistry getServiceRegistry(final String wsdlLocation) {
        /* We cache and reuse registries for the individual WSDL locations: */ 
        if (!registries.containsKey(wsdlLocation)) {
            ServiceRegistry registry = createRegistry(wsdlLocation);
            if (registry == null) {
                return null; 
            } 
            /* 
             * We can't just do the one line below instead of the checks above as we only want to create the registry if 
             * it is absent, but if we'd call `registries.putIfAbsent(wsdlLocation, createRegistry(wsdlLocation));` we 
             * would always create a new instance. And we can't just say put below, even though we are on a 
             * ConcurrentHashMap, as that would introduce a race condition (if somebody puts a registry after the 
             * check). 
             */ 
            registries.putIfAbsent(wsdlLocation, registry);
        } 
        return registries.get(wsdlLocation);
    } 
 
    /** 
     * @param wsdlLocation The WSDL location of the registry to instantiate 
     * @return A service registry instance running at the specified WSDL