 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 3rd, 2003, 12:29 AM
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
By Default Servlet is Single or Multi-Thread Model
Hi all Friends,
I want to clear my doubts By Default Servlet is Single-Thread Model or Multi-Thread Model.Can any one please explain it.
Thanks & Regards
Bikash
|

September 7th, 2003, 12:57 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
By default servelts are intrinsically multithreaded, which means that a single instance can can be accessed by more than one thread.
Go to www.google.com and search on "servlet multithreded".
Cheers
Martyn
|

September 10th, 2003, 01:43 AM
|
Authorized User
|
|
Join Date: May 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
By default a Servlet is Multithreaded and to make a servlet singlethreaded one has to implement the SingleThreadModel interface.
Regards
Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team
|

November 10th, 2004, 12:39 AM
|
Registered User
|
|
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
|
|
There is no such interface as MultiThreadedModel. Servlets are intrinsically multithreaded. This means a single instance can be accessed by more than one thread.
If the container receives multiple requests for one servlet simultaneously, the service () method of that servlet will be executed concurrently in multiple threads
If a servlet implements the SingleThreadModel interface, the container will not execute the service () method in more than one thread simultaneously.
The servlet container may synchronize access to a single instance of the servlet.
However, servicing requests sequentially seriously hurts performance. To avoid the performance problem, a servlet container may create multiple instances of the servlet class.
Different variables in both models thread safe or not:-
1. Single Thread Model:-
Local variables:- are defined within the body of a method. [Levi] Always thread-safe.
Instance variables:- Instance variables are defined within the class body and are separately assigned to each instantiated object. Thread-safe only for SingleThreadModel
Class or static variables:- Only one copy of a class variable exists across all the instances of the object belonging to the class for which it is declared.
Class variables , or static variables, are shared among all instances of a servlet. NEVER thread-safe
(No, not even if servlet implements SingleThreadModel.)
Request attributes :- Always thread-safe
Session attributes:- NEVER thread-safe
Context attributes :- NEVER thread-safe
Regards
Khilan Singh Raghuwanshi
Java Developer
Thanks & Regards
Khilan Singh
|
The Following User Says Thank You to khilansingh For This Useful Post:
|
|

November 11th, 2004, 08:22 AM
|
Registered User
|
|
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i agree with Khilan. it is good answer.
Regards,
Infant Prabu
|

February 22nd, 2007, 05:03 AM
|
Registered User
|
|
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I also agreed with Khilan Singh .
Can i get some more clarifications regarding to avoid the performance problem, a servlet container may create multiple instances of the servlet class.
For(a servlet container may create multiple instances) that, anything we want do in programmatically?
|

September 3rd, 2009, 02:35 PM
|
Registered User
|
|
Join Date: Sep 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by khilansingh
There is no such interface as MultiThreadedModel. Servlets are intrinsically multithreaded. This means a single instance can be accessed by more than one thread.
If the container receives multiple requests for one servlet simultaneously, the service () method of that servlet will be executed concurrently in multiple threads
If a servlet implements the SingleThreadModel interface, the container will not execute the service () method in more than one thread simultaneously.
The servlet container may synchronize access to a single instance of the servlet.
However, servicing requests sequentially seriously hurts performance. To avoid the performance problem, a servlet container may create multiple instances of the servlet class.
Different variables in both models thread safe or not:-
1. Single Thread Model:-
Local variables:- are defined within the body of a method. [Levi] Always thread-safe.
Instance variables:- Instance variables are defined within the class body and are separately assigned to each instantiated object. Thread-safe only for SingleThreadModel
Class or static variables:- Only one copy of a class variable exists across all the instances of the object belonging to the class for which it is declared.
Class variables , or static variables, are shared among all instances of a servlet. NEVER thread-safe
(No, not even if servlet implements SingleThreadModel.)
Request attributes :- Always thread-safe
Session attributes:- NEVER thread-safe
Context attributes :- NEVER thread-safe
Regards
Khilan Singh Raghuwanshi
Java Developer
Thanks & Regards
Khilan Singh
|
Hi Thilan
Its really good way to put info about thread safe variables/attributes.
Best Regards
Dipak S
|
|
 |