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.
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.
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).