You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Warner Onstine <wa...@warneronstine.com> on 2000/09/19 20:32:29 UTC

running tomcat in a thread

Hi all,
I am attempting to get Tomcat [Catalina] to run in its own thread when asked
to start, but am running into some difficulties when attempting to shut it
down.  I am receiving the following message upon attempted shutdown:

Lifecycle Exception: This server has not yet been started.

I have an initialize() method start the thread with all of the parsing of
server.xml, and then the server.start() command (which works properly), with
the appropriate server.await() command (almost identical to
org.apache.catalina.startup.Catalina). Now what is happening when the
terminate() method is called is the exception above.

Any ideas?

-warner


Re: running tomcat in a thread

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Warner Onstine wrote:

> OK, see if this makes sense (and you can tell me where we're wrong ;-).
>
> First assumption: org.apache.catalina.startup.Catalina was designed to be
> run from two different jvm instances.

That is correct -- typically the shutdown is invoked by executing
"$CATALINA_HOME/catalina.sh stop", which starts a new JVM for long enough to
execute the stop logic.

>
> Second assumption: due to this fact, you do not have access to the original
> server instance, so therefore must create your own using createStopMapper
>

Yes, but the only thing that gets configured is the properties from the <Server>
element.  What's really needed is the password string, host name, and port
number.  All the other settings in server.xml are ignored by the stop mapper.

>
> Now once you have a server instance (almost ?) identical to the first you
> can now grab the shutdown and port information to send it the shutdown
> command.
>

Yes ... via a TCP socket (because of the assumption that we are running in a
different JVM).

>
> Herein lies our problem I believe (and I will tell you our fix and see if it
> is the most optimal). When running initialize() as its own thread it has a
> copy of server. When terminate() is called it attempts to change the value
> of server via the createStopMapper and its setServer method. The second
> server instance never gets created properly and therefore the message:
>
> Lifecycle Exception: This server has not yet been started.
>
> Now here is how we got around it - simply remmed out the section on
> xmlMapper and use the current instance of server.
>

That's the right answer ... you have to execute server.stop() on the instance of
server that was started earlier.  Since you are running a thread inside your own
server, you can totally dispense with the shutdown logic in
org.apache.startup.Catalina, and just call server.stop() yourself on that
existing instance.

>
> Does any of this sound right?
>
> -warner

Craig



>
> ----- Original Message -----
> From: "Craig R. McClanahan" <Cr...@eng.sun.com>
> To: <to...@jakarta.apache.org>
> Sent: Tuesday, September 19, 2000 12:13 PM
> Subject: Re: running tomcat in a thread
>
> > Warner Onstine wrote:
> >
> > > Hi all,
> > > I am attempting to get Tomcat [Catalina] to run in its own thread when
> asked
> > > to start, but am running into some difficulties when attempting to shut
> it
> > > down.  I am receiving the following message upon attempted shutdown:
> > >
> > > Lifecycle Exception: This server has not yet been started.
> > >
> > > I have an initialize() method start the thread with all of the parsing
> of
> > > server.xml, and then the server.start() command (which works properly),
> with
> > > the appropriate server.await() command (almost identical to
> > > org.apache.catalina.startup.Catalina). Now what is happening when the
> > > terminate() method is called is the exception above.
> > >
> >
> > That's odd.  The only place that error happens is in
> StandardServer.stop(), and
> > only if the "started" flag is false (it is set to true when you execute
> > StandardServer.start()).  Is there any chance that something else has
> messed
> > with this flag?
> >
> > Other than that, it sounds like you're doing exactly what the standard
> startup
> > stuff does.
> >
> > One possible approach -- you could actually call the main() method of
> > org.apache.catalina.startup.Catalina yourself (from within the new thread)
> and
> > you wouldn't have to do anything special.  All you need is to fake the
> command
> > line arguments that normally get sent (either "start" or "stop" as the
> only one)
> > and you would be using all the normal stuff.
> >
> > >
> > > Any ideas?
> > >
> > > -warner
> > >
> >
> > Craig
> >
> > ====================
> > See you at ApacheCon Europe <http://www.apachecon.com>!
> > Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
> > Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
> >                                     Applications to Tomcat
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

--
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



Re: running tomcat in a thread

Posted by Warner Onstine <wa...@warneronstine.com>.
OK, see if this makes sense (and you can tell me where we're wrong ;-).

First assumption: org.apache.catalina.startup.Catalina was designed to be
run from two different jvm instances.
Second assumption: due to this fact, you do not have access to the original
server instance, so therefore must create your own using createStopMapper

Now once you have a server instance (almost ?) identical to the first you
can now grab the shutdown and port information to send it the shutdown
command.

Herein lies our problem I believe (and I will tell you our fix and see if it
is the most optimal). When running initialize() as its own thread it has a
copy of server. When terminate() is called it attempts to change the value
of server via the createStopMapper and its setServer method. The second
server instance never gets created properly and therefore the message:

Lifecycle Exception: This server has not yet been started.

Now here is how we got around it - simply remmed out the section on
xmlMapper and use the current instance of server.

Does any of this sound right?

-warner
----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, September 19, 2000 12:13 PM
Subject: Re: running tomcat in a thread


> Warner Onstine wrote:
>
> > Hi all,
> > I am attempting to get Tomcat [Catalina] to run in its own thread when
asked
> > to start, but am running into some difficulties when attempting to shut
it
> > down.  I am receiving the following message upon attempted shutdown:
> >
> > Lifecycle Exception: This server has not yet been started.
> >
> > I have an initialize() method start the thread with all of the parsing
of
> > server.xml, and then the server.start() command (which works properly),
with
> > the appropriate server.await() command (almost identical to
> > org.apache.catalina.startup.Catalina). Now what is happening when the
> > terminate() method is called is the exception above.
> >
>
> That's odd.  The only place that error happens is in
StandardServer.stop(), and
> only if the "started" flag is false (it is set to true when you execute
> StandardServer.start()).  Is there any chance that something else has
messed
> with this flag?
>
> Other than that, it sounds like you're doing exactly what the standard
startup
> stuff does.
>
> One possible approach -- you could actually call the main() method of
> org.apache.catalina.startup.Catalina yourself (from within the new thread)
and
> you wouldn't have to do anything special.  All you need is to fake the
command
> line arguments that normally get sent (either "start" or "stop" as the
only one)
> and you would be using all the normal stuff.
>
> >
> > Any ideas?
> >
> > -warner
> >
>
> Craig
>
> ====================
> See you at ApacheCon Europe <http://www.apachecon.com>!
> Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
> Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
>                                     Applications to Tomcat
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>
>


Re: running tomcat in a thread

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Warner Onstine wrote:

> Hi all,
> I am attempting to get Tomcat [Catalina] to run in its own thread when asked
> to start, but am running into some difficulties when attempting to shut it
> down.  I am receiving the following message upon attempted shutdown:
>
> Lifecycle Exception: This server has not yet been started.
>
> I have an initialize() method start the thread with all of the parsing of
> server.xml, and then the server.start() command (which works properly), with
> the appropriate server.await() command (almost identical to
> org.apache.catalina.startup.Catalina). Now what is happening when the
> terminate() method is called is the exception above.
>

That's odd.  The only place that error happens is in StandardServer.stop(), and
only if the "started" flag is false (it is set to true when you execute
StandardServer.start()).  Is there any chance that something else has messed
with this flag?

Other than that, it sounds like you're doing exactly what the standard startup
stuff does.

One possible approach -- you could actually call the main() method of
org.apache.catalina.startup.Catalina yourself (from within the new thread) and
you wouldn't have to do anything special.  All you need is to fake the command
line arguments that normally get sent (either "start" or "stop" as the only one)
and you would be using all the normal stuff.

>
> Any ideas?
>
> -warner
>

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat