On Thu, Dec 22, 2011 at 8:49 PM, Pid <p...@pidster.com> wrote:

> On 22/12/2011 10:34, Konstantin Kolinko wrote:
> > 2011/12/20 S B <sbl...@gmail.com>:
> >> Hi,
> >>
> >> I created and deployed an MBean in my tomcat. It uses datasource to
> connect
> >> to DB.
> >>
> >> My questions is:
> >>
> >> When I create InitialContext() inside MBean's constructor and pass the
> >> envContext to DBManager class to lookup datasource it works fine.
> However
> >> when I create InitialContext() in DBManager  class, it fails.
> >
> > IIRC what InitialContext() sees as its environment highly depends on
> > what classloader is active. That is TCCL =
> > Thread.getContextClassLoader().
> >
> > So while it is run from within web application your TCCL = your
> > webapp's classloader.
> >
> > When it is invoked from jconsole it might be a separate Thread, not
> > related to your web application.
>
>
> Like he ^^^ said.  :)
>
>
> p
>
>
> --
>
> [key:62590808]
>
>
Hi Pid/Konstantin,

yes you are right. I just verified it. When it is invoked from jconsole,
the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d
and when it is run within a web application the clasloader is
WebAppClassloader.

So, how can I force it to use webapp classloader during new
InitialContext() while invoking from jconsole
One possible way is to reuse the initialContext created during server
startup. (pass it as param during invocation from jconsole).

Is there a smarter way ??

Thanks,

Reply via email to