Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multithreading - ServletEndpointContext - question for Richard

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletEndpointContext has request specific methods like getHttpSession() etc

If there is only single JSE which servers all requests,
and if we cache the value of context in ServiceLifecycle.init() method,

how will the same cached object will return different values in different threads ?

Does it make use of ThreadLocal ?
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletEndpointContext has request specific methods like getHttpSession() etc

If there is only single JSE which servers all requests,
and if we cache the value of context in ServiceLifecycle.init() method,

how will the same cached object will return different values in different threads ?

Does it make use of ThreadLocal ?

When caching ServletEndpointContext, it does not imply the ServletEndpointContext also caches a signle session object for its getHTTPSession() method. It might employ ThreadLocal but I'd rather imagine a map is used to manage the session objects and sessionID would be the key for looking up the session objects.
 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
evenif it does not cache the session object
and uses session id

for ServletEndpointContext.getHTTPSession() to return different session objects in different threads at the same time, what else is a possible solution other than ThreadLocal ?
 
Jack Zhou
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are right. I missed the fact that you have to know sessionID. I can only think of ThreadLocal now. However, JDK has some unpublished utility (in com.sun....package)to figure out whch object is calling a method. Similar feature is ablity to figure out the stack trace of an exception. Based on that, there might be some other approaches under the hood.
Any way I guess this is out of beta test's scope.
 
Richard Monson-Haefel
author
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All Java application servers use Thread Specific Storage to ensure that each thread has access to the appropriate context. That's a really wordy way of saying, they use ThreadLocal (or something a lot like it).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic