dev@glassfish.java.net

Re: Thoughts on Threadpool handling of context ClassLoader

From: Ken Cavanaugh <Ken.Cavanaugh_at_Sun.COM>
Date: Fri, 27 Apr 2007 17:02:34 -0700

Lloyd L Chambers wrote:
> I think it would be better to decouple from PEMain by using
> FeatureAvailability to expose the classloader.
>
> Here is one way to do it with FeatureAvailability, whose raison d^etre
> is to decouple dependencies, especially among multiple threads and/or
> unrelated packages.
>
> ...
> public PEMain() {
> // Set the context class loader
> _loader = getClass().getClassLoader();
> Thread.currentThread().setContextClassLoader(_loader);
> FeatureAvailability.getInstance().registerFeature(
> CONTEXT_CLASSLOADER_FEATURE, classloader ); ******
> AdminEventListenerRegistry.addShutdownEventListener(new
> Shutdown());
> _instance = this;
> }
>
> elsewhere:
> ...
> ClassLoader cl =
> FeatureAvailability.getInstance().waitForFeature( ******
> CONTEXT_CLASSLOADER_FEATURE, "<calling site description>" );
> ...
>
> You could use Switch.getSwitch(), but I think FeatureAvailability is
> better for a multi-threaded startup, and introduces no compile-time
> dependencies.
>
>
Multiple threads at startup is not an issue in this case, but I'll be
happy to use
FeatureAvailability if that is the standard mechanism to use for such
things.
Does this means that the Switch should be removed at some point?

Thanks,

Ken.