I develop a web application,deployed some POJO(Business Object) in server,Please confirm whether my understanding correct?
1)When many users access the same business object then server server create several logical or virtual contexts ,in each context all business objects exist,if property of a business object is changed in one context it never change the value of the property in another context.
if many user access server then it do multithreading, the same thread is used for the user still he access the server [ October 02, 2008: Message edited by: jacob deiter ]
The servlet container does not perform magic tricks by itself. What it does provide are:
1. Session mechanism - the session context is attached to a given session ID. Assuming you manage sessions correctly, one session per user. 2. ServletContext - one ServletContext per web application shared by all users. 3. Instance variables - since there is only one instance of a given servlet, all instance variables are shared by all users of that servlet. 4. Request context - each request operates in its own Thread having its own ServletRequest and ServletResponse object seen by no other Thread.
For each request Server will create a new Thread of servlet being requested (or Jsp(but not pojos)) and that thread will instantiate the required pojo(to help it in processing request).. actual pojo will not suffer with any kind of Multithreading..!
--->thing that suffer with multithreading are only instance variables and static variables with in any servlet or jsp..!(Pojo and even beans also never suffer with multithreading..!)
posted 10 years ago
and with in any application there is going to be only one instance of Servlet or Jsp...!
posted 10 years ago
actual pojo will not suffer with any kind of Multithreading..!
please clarify the below also
I read in books that main feature of servlet is multithreading ,for example if I call java object and do some operation inside of servlet's service method(dopost or doge).so if servlet is multithreaded then java object also be multihtreaded or not ? because java object in sevlet's service method
so if servlet is multithreaded then java object also be multihtreaded or not ? because java object in sevlet's service method
The servlet is multithreaded means separate threads are allocated to separate requests. And I dont understand what do you mean by object should be multithreaded. Objects are not multithreaded, the code that accesses them is.
I feel there is a lot of advice of dubious quality being offered here.
Firstly, all Java code is able to be executed by multiple threads, how it manages the threading and what it does under the influence of those threads is the point to consider.
Any shared mutable state running under multiple threads must have its state protected.
Servlet containers manage threads, and the creation, allocation and management of threads is completely up to the container. It is not related to contexts, sessions, users or anything else. (with the exception of William's comments above)
Servlets by nature, are designed to be accessed by multiple threads. If they share their state or access and other shared state, then those objects need to consider their behaviour under multiple threads.
I recommend "Java Concurrency in Action" if you want to get it right. [ October 03, 2008: Message edited by: David O'Meara ]