What's ur point being? When ur servlet implements SingleThreadModel interface, the service method will process request one at a time but not concurrently. If u declare no method in the servlet...then nothing happens..
What peter says is right.you can say that implementing SingleThreadModel makes the whole servlet code "Synchronized" by the use of all the threading properties.It allows one request at a time only. I thnik what peter has put in is the best way to explain.Thanks peter.
Peter's explanation is right on target, although strictly speaking java.lang.Comparable and java.lang.Runnable do define methods. Whenever I see SingleThreadModel, however, the red flags go up. Almost invariably it is an attempt to plug holes in a faulty design. The only real advantage of SingleThreadModel (or the equivalent JSP page directive isThreadSafe="false") is that it prevents two requests from modifying an instance variable at the same time. But you shouldn't be using instance variables in a servlet anyway - there is no reason to do so. You can use local variables within the doGet() method and they will be automatically threadsafe. In other words, instead of this:
If you need to pass a number of local variables between subroutines, you can define a structure class to hold them, define a local variable of that type, and pass that as a parameter between methods:
If you think you need to use instance variables for database connections or other things that need to persist between requests, you are headed for trouble. What you probably want is an HTTP session, instead. At the heart of the problem is that SingleThreadModel results in multiple instances of the servlet running, each with a single thread. The default threading model has a single instance of the servlet and multiple threads running it. If you have an external resource like a database, and you need to synchronize access to it, SingleThreadModel will not have any effect other than to slow everything down. ------------------ Phil Hanna Author of : JSP: The Complete Reference Instant Java Servlets
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Yes, of course they do. How silly of me. Completely agree on the red flags going up. In addition to storing things that really belong in the HttpSession, the SingleThreadModle is sometimes used because the servlet/JSP holds on to some non threadsafe resource, for example, a database connection. Indeed the fact that a server will instantiate your servlet multiple times gives you a kind of primitive connection pool. But in those cases you are much better off with a real, application-scoped connection pool. - Peter
[This message has been edited by Peter den Haan (edited April 24, 2001).]