On Wed, 23 Oct 2002, Veniamin Fichin wrote:
> Date: Wed, 23 Oct 2002 18:43:00 +0400 > From: Veniamin Fichin <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]> > To: Tomcat Users List <[EMAIL PROTECTED]> > Subject: Re: multiple servlet instances? > > Craig R. McClanahan wrote: > > May be my question is not too close to this topic, but it may be > related. It is below... > > >>I was reading in a book today that "JSP implementations are still > >>permitted to create multiple instances of the ... servlet in order to > >>provide improved performance." Does Tomcat/Jasper do this? Might there > >>be multiple instances of a servlet (JSP-generated or otherwise) in my > >>JVM? > > > > You might want to be cautious believing anything that book says about any > > topic, unless it correctly explains what is really going on. What book > > said this? > > > > For anything from Servlet 2.2 on (that's quite a long while back), it is > > not legal for the container to create more than one instance of a > > particular servlet definition *unless* that servlet implements the > > SingleThreadModel interface (or the JSP page has the > > isThreadSafe="false" attribute on its <%@ page %> directive). > > > > The other thing to note is that doing this would not improve performance > > -- at best, it will have zero impact, but it's actually pretty likely to > > be negative (because the container is going to have to manage the multiple > > instances, because the maximum number of simultaneous requests to that > > servlet is now limited to the pool size you've configured, and because > > they take up more memory space). > > > > The only reason that SingleThreadModel exists is to allow you to create a > > servlet or JSP page that stores per-request state information in instance > > variables of the underlying class. This is not a good programming > > practice -- you should instead use local variables only, so that a single > > instance of your servlet or JSP page can handle any number of simultaneous > > requests. > > I'm not familiar with Tomcat internal, but doesn't Tomcat instantiate > a new servlet for each request to it? > No. The same servlet instance is reused for all requests. If you have multiple simultaneous requests to the same servlet, they are running on separate threads. > A have to implement some functionality that related to multiple > instances. I need a servlet which accepts common http requests from > client-side applets. When a next request arrives, servlet must > register a client somehow (for example, store its name and, possibly, > access password) and not to close a connection. And, at any time (may > be seconds, minutes or even hours), it have to send every client some > portion of information based on client's needs. In other words, it's a > server-push. > So, I need to share an information between servlets so each of them > cat send it to corresponding client. > > How can I do this? This task is too complicated for me, since I'm only > starting write in Java. > > Thank you for every answer! > Sounds like you should *really* be using something other than HTTP for this kind of thing, since there is no such thing as a real "server push". You might investigate using some sort of IRC environment, or packages like Jabber <http://www.jabber.org>. It's possible to simulate server-push using web browsers that periodically poll for new information, but the approach doesn't scale very well -- most of the time your server will get hammered by requests that don't end up changing anything, and you can't get information out any faster than the polling interval of your clients. No matter what underlying technology you end up with, I'd suggest doing some research on how multiple threads work in Java. One good starting place for that is the Java Language Tutorial (http://java.sun.com/docs/books/tutorial). Craig -- To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>
