RFR: 8223260: NamingManager should cache InitialContextFactory
Peter Levart
peter.levart at gmail.com
Thu Jan 30 08:56:15 UTC 2020
On 1/30/20 8:59 AM, Peter Levart wrote:
> So if you know that the (implementation class of)
> InitialContextFactory instance is always resolvable (by class name)
> from the ClassLoader you are using for the caching key (the TCCL),
> then this utility might be just right for your purpose.
Thinking of the above, your code may obtain the InitialContextFactory
via two mechanicms:
a) via ServiceLoader.load(InitialContextFactory.class)
b) via the VersionHelper.loadClass(className)
In case of a, the TCCL is used to load the implementation class by the
ServiceLoader spec:
* Creates a new service loader for the given service type, using the
* current thread's {@linkplain java.lang.Thread#getContextClassLoader
* context class loader}.
In case TCCL is null, the system class loader is tried and failing that,
bootstrap class loader.
In case of b, the TCCL is used too, if it is set to a non-null value.
Else the system class loader is used.
So in both cases you should be safe to use the system class loader
returned from ClassLoader.getSystemClassLoader() if TCCL is null as a
key for caching and the InitialContextFactory implementation class will
be resolvable from such key ClassLoader.
Regards, Peter
More information about the core-libs-dev
mailing list