Forums Register Login

thread is logically equal to a context

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
If I understand you correctly, the answer is no.

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.

Bill
+Pie Number of slices to send: Send
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..!)
+Pie Number of slices to send: Send
and with in any application there is going to be only one instance of Servlet or Jsp...!
+Pie Number of slices to send: Send
 

actual pojo will not suffer with any kind of Multithreading..!



Hi Jack

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
+Pie Number of slices to send: Send
 

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.


Hope this helps
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
 


David O'Meara :
I recommend "Java Concurrency in Action" if you want to get it right



Did you mean "Java Concurrency in Practice" ?
+Pie Number of slices to send: Send
That one too
(I'm reading it at the moment though)
+Pie Number of slices to send: Send
let me explain with a practical example..

a context is a party..
context initialized== party started.
there are seperate groups/stacks of methods enjoying party.
so each group/stack makes a seperate thread.
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1394 times.
Similar Threads
session in servers
new instance per user
Thread in JEE
How to save a file inside an application context?
Newbie question on state management
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:37:04.