You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rui Fernandes <ru...@entalpia.com> on 2002/08/28 21:11:09 UTC

Servlet Instances

How should I control how many instances I want of a given servlet?
In my case I would like just one.


Re: Servlet Instances

Posted by Bill Barker <re...@verizon.net>.
"Nikola Milutinovic" <Ni...@ev.co.yu> wrote in message
news:003b01c24f1c$fa2e6ba0$6e3da8c0@ev.co.yu...
> >How should I control how many instances I want of a given servlet?
> >In my case I would like just one.
>
> I don't think you can control that, usually there is only one instance per
Servlet Engine. Are you trying to say that you don't want to have more than
one REQUEST being handled by the servlet at one time (a complete request)?
Then look at SingleThreadModel in Servlet specification.
>

If you don't use STM, then there can be at most one instance of your Servlet
per web-app.  However, if your servlet lives in a jar in
$CATALINA_HOME/shared/lib there is nothing to prevent you deploying it in
hundreds of web-apps (each with a separate instance).  Note that separate
Hosts count as separate web-apps as far as Tomcat is concerned.

If you do use STM, then you have no control at all over how many instances
of your servlet will be created.  All that you know is that no two threads
will access the same instance at the same time.  All top-level release
versions of Tomcat currently implement STM pooling (at least by default).



> Nix.
>





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Servlet Instances

Posted by Bill Barker <re...@verizon.net>.
I'm guessing that you have either 2 unused Hosts or Connectors (or some
combination thereof) in your server.xml.  This will cause the servlet to get
initialized multiple times.

"Rui Fernandes" <ru...@entalpia.com> wrote in message
news:009b01c24f48$9ab9c260$4600a8c0@server...
> No,
> Is just like that.
> But I change things with static variables to control that servlets don't
> instantiate what others instantiated before, and share access to the
> necessary classes through static references.
> But I find that this doesn't solve the problem... My conclusion, somehow
> there are 3 Tomcats running!?!? But only one seems to be responsible for
> remote calls.
>
> Strange, very strange indeed.... just can't get it.
>
>
> ----- Original Message -----
> From: Nikola Milutinovic <Ni...@ev.co.yu>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Sent: Thursday, August 29, 2002 12:29 PM
> Subject: Re: Servlet Instances
>
>
> > > No, I am saying I have three instances of the same servlet. Only one
> appears
> > > to be receiving the requests, but if things are like you say then
what's
> > > going on with Tomcat? Are you saying I have three Tomcats running,
even
> > > thought I called startup only once?
> >
> > Are you sure? Could it be that your mixing instances of a class with
> threads running in the engine?
> >
> > Otherwise it is very strange.
> >
> > Nix.
> >





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Servlet Instances

Posted by Rui Fernandes <ru...@entalpia.com>.
No,
Is just like that.
But I change things with static variables to control that servlets don't
instantiate what others instantiated before, and share access to the
necessary classes through static references.
But I find that this doesn't solve the problem... My conclusion, somehow
there are 3 Tomcats running!?!? But only one seems to be responsible for
remote calls.

Strange, very strange indeed.... just can't get it.


----- Original Message -----
From: Nikola Milutinovic <Ni...@ev.co.yu>
To: Tomcat Users List <to...@jakarta.apache.org>
Sent: Thursday, August 29, 2002 12:29 PM
Subject: Re: Servlet Instances


> > No, I am saying I have three instances of the same servlet. Only one
appears
> > to be receiving the requests, but if things are like you say then what's
> > going on with Tomcat? Are you saying I have three Tomcats running, even
> > thought I called startup only once?
>
> Are you sure? Could it be that your mixing instances of a class with
threads running in the engine?
>
> Otherwise it is very strange.
>
> Nix.
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Servlet Instances

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
> No, I am saying I have three instances of the same servlet. Only one appears
> to be receiving the requests, but if things are like you say then what's
> going on with Tomcat? Are you saying I have three Tomcats running, even
> thought I called startup only once?

Are you sure? Could it be that your mixing instances of a class with threads running in the engine?

Otherwise it is very strange.

Nix.

RE: Servlet Instances

Posted by Rui Fernandes <ru...@entalpia.com>.
No, I am saying I have three instances of the same servlet. Only one appears
to be receiving the requests, but if things are like you say then what's
going on with Tomcat? Are you saying I have three Tomcats running, even
thought I called startup only once?


----- Original Message -----
From: Nikola Milutinovic <Ni...@ev.co.yu>
To: Tomcat Users List <to...@jakarta.apache.org>
Sent: Thursday, August 29, 2002 7:28 AM
Subject: Re: Servlet Instances


> >How should I control how many instances I want of a given servlet?
> >In my case I would like just one.
>
> I don't think you can control that, usually there is only one instance per
Servlet Engine. Are you trying to say that you don't want to have more than
one REQUEST being handled by the servlet at one time (a complete request)?
Then look at SingleThreadModel in Servlet specification.
>
> Nix.
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Servlet Instances

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
>How should I control how many instances I want of a given servlet?
>In my case I would like just one.

I don't think you can control that, usually there is only one instance per Servlet Engine. Are you trying to say that you don't want to have more than one REQUEST being handled by the servlet at one time (a complete request)? Then look at SingleThreadModel in Servlet specification.

Nix.

RE: Servlet Instances

Posted by Rui Fernandes <ru...@entalpia.com>.
People say the normal on Tomcat should be only one instance... I am getting
three...

----- Original Message -----
From: Randy Secrist <to...@secristfamily.com>
To: Tomcat Users List <to...@jakarta.apache.org>
Sent: Thursday, August 29, 2002 6:48 AM
Subject: Re: Servlet Instances


> You can't explicitly control how many instances a container may create of
> your servlet since you don't have control over the container code.
(Unless
> you hack the container that is.)  If you do hack, you might as well write
> your own servlet specification since you would have to change many of the
> interfaces.  This isn't very reasonable.  (You can't make the constructor
> private and make it a singleton since a servlet must conform to a
> HttpServlet interface.)
>
> What most people do when they have this need, is let the container call
the
> servlet to it's hearts content, and ensure that any objects the servlet
> references are only instantiated one time.  (Via singletons, static
classes,
> etc.).  However - since these objects usuallly have synchronized methods,
if
> your site gets a lot of traffic, the container won't be taking advantage
of
> it's multi threaded abilities, and each request will have to block on any
> synchronized sections of code you have.
>
> In a large traffic application, I would use a DBMS / EJB system which
> offloads much of the servlet transactionality.
>
> Randy
>
> ----- Original Message -----
> From: "Rui Fernandes" <ru...@entalpia.com>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Wednesday, August 28, 2002 1:11 PM
> Subject: Servlet Instances
>
>
> How should I control how many instances I want of a given servlet?
> In my case I would like just one.
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Servlet Instances

Posted by Randy Secrist <to...@secristfamily.com>.
You can't explicitly control how many instances a container may create of
your servlet since you don't have control over the container code.  (Unless
you hack the container that is.)  If you do hack, you might as well write
your own servlet specification since you would have to change many of the
interfaces.  This isn't very reasonable.  (You can't make the constructor
private and make it a singleton since a servlet must conform to a
HttpServlet interface.)

What most people do when they have this need, is let the container call the
servlet to it's hearts content, and ensure that any objects the servlet
references are only instantiated one time.  (Via singletons, static classes,
etc.).  However - since these objects usuallly have synchronized methods, if
your site gets a lot of traffic, the container won't be taking advantage of
it's multi threaded abilities, and each request will have to block on any
synchronized sections of code you have.

In a large traffic application, I would use a DBMS / EJB system which
offloads much of the servlet transactionality.

Randy

----- Original Message -----
From: "Rui Fernandes" <ru...@entalpia.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, August 28, 2002 1:11 PM
Subject: Servlet Instances


How should I control how many instances I want of a given servlet?
In my case I would like just one.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>