If you pass an AsyncContext to a random other thread (which is not
necessarily container managed), then the fact that code in this other
thread gets hold of this context, doesn't set up the TLS stuff needed for
@RequestScoped etc, does it?
If so, how would this technically work?
This is different from container managed threads which get work submitted
to it (like Concurrency spec executor service and @Asynchronous). They have
an opportunity to set up and tear down the contexts before and after
working on the unit respectively.
For the AsyncContext case, what about something like the following in the
thread that in whatever way gets hold of the AsyncContext
beanmanager.initScope(RequestScoped.class, request);
or with a guard:
beanmanager.initScopeIfNotActive(RequestScoped.class, request);
Would that work?
On Sun, Mar 20, 2016 at 9:51 PM, Mark Struberg <struberg(a)yahoo.de> wrote:
I think the current spec wording already defines what happens in
that
case. At least there are TCK tests for it.
LieGrue,
strub
On Sunday, 20 March 2016, 21:37, arjan tijms <arjan.tijms(a)gmail.com>
wrote:
>
>On Sun, Mar 20, 2016 at 6:36 PM, Manfred Riem <mnriem(a)gmail.com> wrote:
>
>Why is changing @RequestScoped out of the question?
>>
>>
>>From my perspective when an AsyncContext is started the request is still
there.
>>
>>
>>It is just being served by a different thread.
>
>
>With just AsyncContext the original request thread can end and a new
thread can write to the response. Both of them can access the request
object after the AsyncContext has been handed to the second thread. But the
second thread is not necessarily "connected" to anything, is it? It's just
any random thread that gets the AsyncContext object passed in.
>
>
>
>Would it work here if there was a public CDI API available to activate
the request scope (and session scope possibly) from a given instance of
ServletRequest?
>
>
>Regardless, this is a slightly different problem from when a given
request thread submits work to a Concurrency spec executor.
>
>
>Kind regards,
>Arjan Tijms
>
>