wood burning stoves 2.0*
The moose likes Servlets and the fly likes Starting servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Starting servlets" Watch "Starting servlets" New topic
Author

Starting servlets

John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
Hi,

I've been reading on servlets and I'm still confused with the basics.

only 1 instance of servlet services multiple client requests. Is there a situation when it creates multiple instances?

Regards,
John Eipe


www.cs-repository.info
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

When a client makes a connection for a servlet, an instance of the servlet class is created and the new thread uses it to service the request.

Container does not create new instance of the servlet for each request, there can be multiple threads running the service method of the same servlet instance. and hence the class variables may create issues. Look at the servlet life cycle


[Servlet tutorial] [Servlet 3.0 Cook Book]
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
@sudhir nim
Is that your blog?

Thanks,
John Eipe
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

I believe, on some web containers, multiple instances of Servlets implementing SingleThreadModel are created to handle the requests and they seem to reliably thread-safe.


S.D. MADHAN
Not many get the right opportunity !
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

No, SingleThreadModel is deprecated.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41052
    
  43
multiple instances of Servlets implementing SingleThreadModel are created to handle the requests and they seem to reliably thread-safe.

While that will lead to multiple instances being created, that by itself is not sufficient to guarantee thread-safety. Which, as Bear pointed out, is why it's deprecated and should not be used.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: Starting servlets
 
Similar Threads
Servlets
are request attributes and session attributes thread safe?
Are multiple http servlets possible ?
Q:17 JavaRanck mock exam
multiple instances of same servlet class in WebLogic ?