Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread is logically equal to a context

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jack Doson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..!)
 
Jack Doson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and with in any application there is going to be only one instance of Servlet or Jsp...!
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


Did you mean "Java Concurrency in Practice" ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That one too
(I'm reading it at the moment though)
 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic