Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

multithreading - ServletEndpointContext - question for Richard

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic