Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session - Concurrency issue  RSS feed

 
Karan Sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one basic but confusing question -
Servlets are intrinsically multithreaded. This means a single instance can be accessed by more than one thread. So does this mean that if I am calling a Static Class from the jsp (which will actually be a servlet), then I will have to look into the concurrency issues.
For eg, lets say if I have a static class which returns me something from the session:
<<StaticClass>>SessionHandler
public UserObject getObject(Constants.USERVALUEOBJECT, session){
return (UserObject)session.getAttribute(Constants.USERVALUEOBJECT);
}

In this case do I have to take care of the concurrency issues. What I dont understand here is that the "session" parameter passed to the Staticclass method is particular to one thread so the StaticClass is always going to operate on that, so there should not be any concurrency issues involved...I m confused here..please help.

Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66186
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct, threads that run in different sessions will not have a problem since you are passing the particular session into the method.
And, in this case, even threads in the same session will not cause any problems since you are only fetching an attribute from the session. Where you can get into trouble is when different theads start modifying things. So if your page is going to modify the object that its gets from the session, that's a point of contention. If not, no worries.
hth,
bear
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!