On 23/12/2011 04:57, S B wrote: > 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 ??
I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808]
signature.asc
Description: OpenPGP digital signature