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 14:16:34 -0700

Lloyd L Chambers wrote:
> One thought:
>
> Take a look at the AtStartup and LoadMBeanServer classes which are
> used in their own threads from PEMain.main(). Similar threads can be
> started later, say in PEMain.run().
>
> You could kick off a similar thread to initialize a thread pool. You
> could also (optionally) make the classloader and/or thread pool(s)
> available via FeatureAvailability:
>
> FeatureAvailability.getInstance().registerFeature(
> CONTEXT_ClASSLOADER_FEATURE, classloader );
>
> Later code can call FeatureAvailability.getInstance().waitForFeature(
> CONTEXT_ClASSLOADER_FEATURE, ... ) and will block until it's ready.
>
> I'm not sure that's the right solution here, but I thought I'd mention
> it.
>
I don't think a separate thread is needed. In fact, all I really need
is to save a ClassLoader
at startup that can be used later when the ThreadPool is created. It
looks like PEMain
already does this: the constructor is:

    public PEMain() {
        // Set the context class loader
        _loader = getClass().getClassLoader();
        Thread.currentThread().setContextClassLoader(_loader);
        AdminEventListenerRegistry.addShutdownEventListener(new Shutdown());
        _instance = this;
    }

So clearly the _loader data member contains exactly what I want. Is
adding an accessor
method to PEMain to get _loader reasonable? Then I could simply use

PEMain.getInstance().getDefaultContextClassLoader()

to access what I need. This could be passed to the ThreadPoolImpl
constructor
(which requires an ORB change) in the
S1ASThreadPoolManager.createThreadPools
call.

Thanks,

Ken.