Hi,

Whenever a HTTP request comes to the web container (Tomcat, Jetty, ...) a
Servlet or a Filter is used to handle it.
In the case of Wicket this is WicketFilter. I.e. WicketFilter is the entry
and exit point for request handling.
As I explained earlier - each http request is handled by exactly one thread
[1]. I.e. this thread enters into WicketFilter#doFilter(), does the work,
and finally exits from this method.
At "exit time" WicketFilter clears the ThreadLocal (ThreadContext), so the
Application, Session and RequestCycle are no more available in this thread.
They will be set again next time this thread is reused by the web container
to serve a http request for Wicket page/resource.

If a second request comes while the first one is still handling the first
request then a completely new ThreadLocal is used for it.
Both ThreadLocals refer to the same Application instance.
If the sessionid is the same then both threadlocals will point to the same
Session instance. Otherwise they will have different Session instances.
The RequestCycle instance is fresh new for every http request.


1. Is not valid in case of Servlet 3.0+ Async servlet, but as I said this
is not supported for Wicket pages.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Oct 14, 2015 at 7:32 AM, santhosh <[email protected]>
wrote:

> Thank you very much for the reply.
>
> Your cleared my doubt which is hammering me from 1 week. Your post
> triggered
> me one more doubt, which is:
>
> I have seen in the wicket implementation code that ThreadContext class has
> a
> references to Application, Session and RequestCycle. So whenever the
> request
> comes, the thread that works for that request creates the ThreadLocal
> object
> in which that thread gets Application, Session and RequestCycle object
> singletons to it, so it will only have access to it until the response is
> generated.
>
> So what is scenario when next request comes in, does a new thread works it
> or the same thread which process the earlier request for that user is only
> allotted to do the job. Why i am asking is, the thread which processed the
> first request is having the session reference, so if a new thread is
> allocated for the next request, that new thread has to get its own
> ThreadLocal again, which will not have the access to the earlier session
> object.
>
> So how are we managing the user session data during his entire active cycle
> in the website. I mean what if we have to use data gathered in one page in
> another page(if we are using 2 thread to process request from 2 pages, they
> cant get to each others session data).
>
> Could you please clarify me.
>
> Thanks in Advance
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/ThreadLocal-usage-for-managing-session-in-Wicket-tp4672215p4672220.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to