Reputation: 7428
How is a session object attached to each thread of a servlet? I believe its not a ThreadLocal, so how is it attached to each servlet thread?
Upvotes: 1
Views: 1060
Reputation: 118641
It's not attached to the Servlet thread, it's attached to the HttpServletRequest. Each invocation of the Servlet is passed a HttpServletRequest and an HttpServeltResponse. So, they're just local variables to the Servlet instance -- nothing to do with the thread.
Upvotes: 2
Reputation: 162801
A JSESSIONID variable gets set in the client's cookie (or URL sometimes) and the container uses the JSESSIONID to look up the appropriate session for the given request.
Upvotes: 1