Protocol.registerProtocol for apache HttpClient 是否会导致全局静态更改?

Does Protocol.registerProtocol for apache HttpClient cause a global static change?

我遇到了一些使用

的代码

Protocol.registerProtocol

尝试为请求阻止一些 TLS 密码,并根据其他因素有时重新启用它来重试请求。

但是 Protocol.registerProtocol 是否会导致全局变化 - 即其他线程是否会受此影响?

这是有问题的代码:

protected static HostConfiguration buildTLSConfig(String uri, HostConfiguration config,
        boolean blockTLS1)
        throws MalformedURLException
{
        scheme = "https";
        if (baseHttps == null)
        {
            baseHttps = Protocol.getProtocol(scheme);
            baseFactory = baseHttps.getSocketFactory();
        }

        URL newUrl = new URL(uri);

        defaultPort = baseHttps.getDefaultPort();

        if (blockTLS1)
        {
            ProtocolSocketFactory customFactory =
                    new CustomHttpsSocketFactory(baseFactory, TLS_PREFERRED_PROTOCOLS);
            Protocol applyHttps = new Protocol(scheme, customFactory, defaultPort);
            Protocol.registerProtocol(scheme, applyHttps);
            config.setHost(newUrl.getHost(), defaultPort, applyHttps);
        }
        else
        {
            Protocol.registerProtocol(scheme, baseHttps);
            config.setHost(newUrl.getHost(), defaultPort, baseHttps);
        }

        return config;
}

是的,所有线程都会受到更改的影响。

如果我们查看 org.apache.commons.httpclient.protocol.Protocol,我们会看到一个全局协议 Map

    /** The available protocols */
    private static final Map PROTOCOLS = Collections.synchronizedMap(new HashMap());

并且registerProtocol()简单地修改它:

public static void registerProtocol(String id, Protocol protocol) {

    // . . .

    PROTOCOLS.put(id, protocol);
}

至少它是同步的,所以修改期间不会有竞争。