You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Micael <ca...@harbornet.com> on 2003/03/25 01:29:02 UTC
Servlet init() versus doPost() Classloading???
I am having a problem with a daemon I want to create at startup. I have a
singleton daemon that I used to load on startup in the init(ServletConfig)
method of a servlet. The problem is that this ends up creating two
versions that then run concurrently and duplicate everything they each are
doing. So, I had to quite doing that and instead kickstart the daemon by
putting it in doPost(HttpServletRequest, HttpServletResponse) instead. I
am really not quite sure what the classloader issues are here.
I would like to kickstart the daemon on startup, because then I can avoid
having to have clients get it going on their server with a call to
http://localhost/kickstart where /kickstart is the mapping that calls the
servlet with the daemon in doPost(HttpServletRequest,
HttpServletResponse). Does someone have an idea. I am sure there are a
lot of good ideas (there must be) but they are not coming to me
immediately. I don't know that much about classloaders. I am not sure how
the second version of the daemon is getting loaded, i.e. what other
classloader is doing that. I know that each servlet has its own
classloader. How that translates into the difference between init and
doPost and the difference between startup of Tomcat and startup by call via
doPost is dark to me.
I would just go read more intensively on classloaders, if I could know that
was the way to solve this dilemma of my own making.
Thanks for any assistance on this.
Micael
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank you
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Servlet init() versus doPost() Classloading???
Posted by Justin Ruthenbeck <ju...@nextengine.com>.
Rahul --
Yeah, you're right. The problem, though, is that he's seeing two instances
start when a servlet's init() method is called. This means the singleton
doesn't have the "mechanism to track the daemon state (running,
notStarted)" in place.
We agree. My point was just that moving the code that calls into the
singleton from the init() method to the doPost() won't fix anything. If
the singleton is broken, he'll have the same problem if he hits the URL
twice. The problem lies in the singleton object.
justin
At 05:27 PM 3/24/2003, you wrote:
>Hi Justin,
>
>Since the daemon is a singleton.... i think... hitting the same URL twice
>shouldn't be a problem if mechanism to track the daemon state (running,
>notStarted ) is in place.
>
>The problem as you said might be in the configuration.
>
>Cheers,
>
>Rahul
>
>
>----- Original Message -----
>From: "Justin Ruthenbeck" <ju...@nextengine.com>
>To: "Tomcat Users List" <to...@jakarta.apache.org>
>Sent: Tuesday, March 25, 2003 12:43 PM
>Subject: Re: Servlet init() versus doPost() Classloading???
>
>
> > Hi Micael,
> >
> > Seems you're sidestepping the real problem by trying to initialize with a
> > doPost call ... the init() method is, afterall, meant for such
> > initialization. ;) Won't you have the same problem is you hit the URL
> > twice?
> >
> > If there are two copies of your deamon thread starting, then the problem
>is
> > in the code that starts them and can be changed to get the desired
> > behavior. Before going into thoughts on that, is there anything non-basic
> > about your setup that would complicate the problem (such as clustered
> > Tomcats, multiple JVMs, or other code that can start this daemon)?
> >
> > My apologies if you're absolutely sure you want to do this from a
> > doPost(). (?!)
> >
> > justin
____________________________________
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential
See http://www.nextengine.com/confidentiality.php
____________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Servlet init() versus doPost() Classloading???
Posted by Rahul <ra...@excibir.co.nz>.
Hi Justin,
Since the daemon is a singleton.... i think... hitting the same URL twice
shouldn't be a problem if mechanism to track the daemon state (running,
notStarted ) is in place.
The problem as you said might be in the configuration.
Cheers,
Rahul
----- Original Message -----
From: "Justin Ruthenbeck" <ju...@nextengine.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, March 25, 2003 12:43 PM
Subject: Re: Servlet init() versus doPost() Classloading???
> Hi Micael,
>
> Seems you're sidestepping the real problem by trying to initialize with a
> doPost call ... the init() method is, afterall, meant for such
> initialization. ;) Won't you have the same problem is you hit the URL
> twice?
>
> If there are two copies of your deamon thread starting, then the problem
is
> in the code that starts them and can be changed to get the desired
> behavior. Before going into thoughts on that, is there anything non-basic
> about your setup that would complicate the problem (such as clustered
> Tomcats, multiple JVMs, or other code that can start this daemon)?
>
> My apologies if you're absolutely sure you want to do this from a
> doPost(). (?!)
>
> justin
>
>
> At 04:29 PM 3/24/2003, you wrote:
> >I am having a problem with a daemon I want to create at startup. I have
a
> >singleton daemon that I used to load on startup in the
init(ServletConfig)
> >method of a servlet. The problem is that this ends up creating two
> >versions that then run concurrently and duplicate everything they each
are
> >doing. So, I had to quite doing that and instead kickstart the daemon by
> >putting it in doPost(HttpServletRequest, HttpServletResponse) instead. I
> >am really not quite sure what the classloader issues are here.
> >
> >I would like to kickstart the daemon on startup, because then I can avoid
> >having to have clients get it going on their server with a call to
> >http://localhost/kickstart where /kickstart is the mapping that calls the
> >servlet with the daemon in doPost(HttpServletRequest,
> >HttpServletResponse). Does someone have an idea. I am sure there are a
> >lot of good ideas (there must be) but they are not coming to me
> >immediately. I don't know that much about classloaders. I am not sure
> >how the second version of the daemon is getting loaded, i.e. what other
> >classloader is doing that. I know that each servlet has its own
> >classloader. How that translates into the difference between init and
> >doPost and the difference between startup of Tomcat and startup by call
> >via doPost is dark to me.
> >
> >I would just go read more intensively on classloaders, if I could know
> >that was the way to solve this dilemma of my own making.
> >
> >Thanks for any assistance on this.
> >
> >Micael
>
>
> ____________________________________
> Justin Ruthenbeck
> Software Engineer, NextEngine Inc.
> justinr - AT - nextengine DOT com
> Confidential
> See http://www.nextengine.com/confidentiality.php
> ____________________________________
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Servlet init() versus doPost() Classloading???
Posted by Justin Ruthenbeck <ju...@nextengine.com>.
Hi Micael,
Seems you're sidestepping the real problem by trying to initialize with a
doPost call ... the init() method is, afterall, meant for such
initialization. ;) Won't you have the same problem is you hit the URL
twice?
If there are two copies of your deamon thread starting, then the problem is
in the code that starts them and can be changed to get the desired
behavior. Before going into thoughts on that, is there anything non-basic
about your setup that would complicate the problem (such as clustered
Tomcats, multiple JVMs, or other code that can start this daemon)?
My apologies if you're absolutely sure you want to do this from a
doPost(). (?!)
justin
At 04:29 PM 3/24/2003, you wrote:
>I am having a problem with a daemon I want to create at startup. I have a
>singleton daemon that I used to load on startup in the init(ServletConfig)
>method of a servlet. The problem is that this ends up creating two
>versions that then run concurrently and duplicate everything they each are
>doing. So, I had to quite doing that and instead kickstart the daemon by
>putting it in doPost(HttpServletRequest, HttpServletResponse) instead. I
>am really not quite sure what the classloader issues are here.
>
>I would like to kickstart the daemon on startup, because then I can avoid
>having to have clients get it going on their server with a call to
>http://localhost/kickstart where /kickstart is the mapping that calls the
>servlet with the daemon in doPost(HttpServletRequest,
>HttpServletResponse). Does someone have an idea. I am sure there are a
>lot of good ideas (there must be) but they are not coming to me
>immediately. I don't know that much about classloaders. I am not sure
>how the second version of the daemon is getting loaded, i.e. what other
>classloader is doing that. I know that each servlet has its own
>classloader. How that translates into the difference between init and
>doPost and the difference between startup of Tomcat and startup by call
>via doPost is dark to me.
>
>I would just go read more intensively on classloaders, if I could know
>that was the way to solve this dilemma of my own making.
>
>Thanks for any assistance on this.
>
>Micael
____________________________________
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential
See http://www.nextengine.com/confidentiality.php
____________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org