On Tue, Dec 27, 2011 at 4:53 PM, Pid * <p...@pidster.com> wrote:

> On 27 Dec 2011, at 11:16, S B <sbl...@gmail.com> wrote:
>
> > On Tue, Dec 27, 2011 at 4:06 PM, Pid * <p...@pidster.com> wrote:
> >
> >> On 27 Dec 2011, at 01:33, S B <sbl...@gmail.com> wrote:
> >>
> >>> On Mon, Dec 26, 2011 at 3:28 PM, Pid * <p...@pidster.com> wrote:
> >>>
> >>>> On 26 Dec 2011, at 09:50, S B <sbl...@gmail.com> wrote:
> >>>>
> >>>>> On Sat, Dec 24, 2011 at 6:29 PM, Pid <p...@pidster.com> wrote:
> >>>>>
> >>>>>> 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]
> >>>>>>
> >>>>>>
> >>>>> Hi,
> >>>>>
> >>>>> un-registering of mbean doesn't happen until servlet's destroy method
> >> is
> >>>>> called.
> >>>>> Actually, registration of bean happen only once, ie during server
> >>>> startup.
> >>>>> This time mbean's constructor is called and it is registered with
> MBean
> >>>>> server.
> >>>>> (I was wrong earlier when I said, constructor is called on each
> >>>> invocation
> >>>>> of reload() method from jconsole. sorry about that. i was lill
> >> confused.)
> >>>>>
> >>>>> MBean is never re-created. It is created only once and registered
> only
> >>>> once.
> >>>>>
> >>>>> actual flow is:
> >>>>>
> >>>>> click reload() on jconsole gui.
> >>>>> *it causes constructor of MBeanImpl to run. (verified from logs.)*
>  --
> >>>> *Wrong.
> >>>>> pls disregard this statement.*
> >>>>> calls reload() defined in MBeanImpl.
> >>>>> calls DBManager.reload()
> >>>>> inside DBManager.reload() it fails at InitialContext initContext =
> new
> >>>>> InitialContext();
> >>>>> the exception is  -  javax.naming.NoInitialContextException: Cannot
> >>>>> instantiate class: org.apache.naming.java.javaURLContextFactory [Root
> >>>>> exception is java.lang.ClassNotFoundException:
> >>>>> org.apache.naming.java.javaURLContextFactory]
> >>>>
> >>>> OK, but what is the purpose of DBManager.reload()?
> >>>>
> >>>>
> >>>> p
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >>>> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>>>
> >>>>
> >>>
> >>> Hi Pid, Marry Christmas !!!
> >>> Purpose of DBManager.reload() is to load some application specific data
> >>> from DB. Pls don't consider reload() as reload of MBean.
> >>> reload() can better be renamed as loadData().
> >>>
> >>> when I invoke reload() from jconsole my application is suppose to make
> a
> >> db
> >>> connection and load app specific data from database.
> >>
> >> OK, so why not retain a reference to the DataSource that you're
> >> getting the connection from?
> >>
> >>
> >> p
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>
> >>
> > yes. thats one possible workaround. I followed similar approach and
> > retailed reference of Context (which i used to get datasource during
> > invocation from jconsole).
> > This approach works.
> > And as Konstantin earlier said it is because of different class loaders
> > that I can't do "new InitialContext()" during invocation from jconsole.
> > *My question is:  how can I force it to use webapp classloader during new
> > InitialContext() while invoking from jconsole.*
> >
> > is there a way to do something like
> > InitialContext.useClassLoader(webaappClassLoader)
> > ?
> > During server startup InitialContext() used webapp classloader and during
> > invocation of mbean from jconsole it was some other classloader hence "
> new
> > InitialContext()" failed.
> >
> > you got my question ?
>
>
> Yes. I got it.
>
> I'm not trying to find a solution because I'm not sure why you insist
> on doing things the hard way when there is a perfectly reasonable
> alternative.
>
>
> p
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>
That's fine. I just wanted to confirm whether the reference-retention
approach is the smartest one or there are any better solution available.
Thanks for your help.
:)

Reply via email to