<div dir="ltr">Okay, so request scope<span style="font-size:12.8000001907349px"> is not associated with web requests, but with &quot;invocation chains&quot;. I thought so because session scope is </span><span style="font-size:12.8000001907349px">associated </span><span style="font-size:12.8000001907349px">with web requests and Weld is backing it&#39;s request scope implementation with request attributes.</span><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">So the SPI has a need for dispatching async work in new threads, at it&#39;s best with most common scopes (</span><span style="font-size:12.8000001907349px">application, session and request</span><span style="font-size:12.8000001907349px">) being active? </span></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Application does not seem to be a problem. Request is always a new context per thread. The question is, whether session scope is propagated to newly spawned threads, when using this SPI? Afaik it&#39;s currently only active during web requests. From an implementation point of view it could be tricky to dis</span><span style="font-size:12.8000001907349px">associate current session scope impls from servlet session lifecycle. On the other side: from a user point of view it would be nice, if I dispatch work via some SPI, the processing of work is done in the same &quot;user context&quot;.</span></div><div><div><span style="font-size:12.8000001907349px"><br></span></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-19 18:18 GMT+01:00 Romain Manni-Bucau <span dir="ltr">&lt;<a href="mailto:rmannibucau@gmail.com" target="_blank">rmannibucau@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">today request scope = thread scope and we can&#39;t help on it. I recall<br>
having said web scopes should stay aligned on web behavior but answer<br>
was quite clear: this is not what is in the spec (at least in<br>
intention term) which is fine but today request scope is also used in<br>
batches for thread scope behaviors so too late to change. Servlet spec<br>
can have its own web scope now which would allow to fix this and go<br>
ahead.<br>
<span class="im HOEnZb"><br>
<br>
Romain Manni-Bucau<br>
@rmannibucau<br>
<a href="http://www.tomitribe.com" target="_blank">http://www.tomitribe.com</a><br>
<a href="http://rmannibucau.wordpress.com" target="_blank">http://rmannibucau.wordpress.com</a><br>
<a href="https://github.com/rmannibucau" target="_blank">https://github.com/rmannibucau</a><br>
<br>
<br>
</span><div class="HOEnZb"><div class="h5">2015-02-19 18:13 GMT+01:00 Sven Linstaedt &lt;<a href="mailto:sven.linstaedt@gmail.com">sven.linstaedt@gmail.com</a>&gt;:<br>
&gt; The question remains: Does CDI has to make sure, request scope implies<br>
&gt; single threaded access, because most existing applications are not aware of<br>
&gt; possible threading issues for request scoped beans?<br>
&gt;<br>
&gt; I do not think so. Afaik the same problem has affected session scoped beans<br>
&gt; before servlet 3.0, but application developers are hopefully more aware of<br>
&gt; it.<br>
&gt;<br>
&gt; 2015-02-19 17:52 GMT+01:00 Romain Manni-Bucau &lt;<a href="mailto:rmannibucau@gmail.com">rmannibucau@gmail.com</a>&gt;:<br>
&gt;&gt;<br>
&gt;&gt; @Mark: for the container usage only but nothing prevents you to use it<br>
&gt;&gt; elsewhere at your own risk<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Romain Manni-Bucau<br>
&gt;&gt; @rmannibucau<br>
&gt;&gt; <a href="http://www.tomitribe.com" target="_blank">http://www.tomitribe.com</a><br>
&gt;&gt; <a href="http://rmannibucau.wordpress.com" target="_blank">http://rmannibucau.wordpress.com</a><br>
&gt;&gt; <a href="https://github.com/rmannibucau" target="_blank">https://github.com/rmannibucau</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2015-02-19 17:40 GMT+01:00 Mark Struberg &lt;<a href="mailto:struberg@yahoo.de">struberg@yahoo.de</a>&gt;:<br>
&gt;&gt; &gt; Even in Servlets-3.0 a ‚Request‘ is only attached to exactly one single<br>
&gt;&gt; &gt; thread AT THE SAME TIME afaik.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; So they can switch a Request from one thread to another one, but there<br>
&gt;&gt; &gt; is always just a single one accessing it at the same time. At least that is<br>
&gt;&gt; &gt; what I did understand.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; LieGrue,<br>
&gt;&gt; &gt; strub<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; Am 19.02.2015 um 17:33 schrieb Sven Linstaedt<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:sven.linstaedt@gmail.com">sven.linstaedt@gmail.com</a>&gt;:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hi,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; and sorry for spontaneously dropping in. Just to clarify some personal<br>
&gt;&gt; &gt;&gt; questions/assumptions:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 1. Regarding threading the current spec only states that &quot;A context may<br>
&gt;&gt; &gt;&gt; be associated with one or more threads&quot;.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 2. It is nowhere stated that @RequestScoped beans are inherently thread<br>
&gt;&gt; &gt;&gt; safe. Thread safety was implied from the servlet spec, because the scope<br>
&gt;&gt; &gt;&gt; backing container (ServletRequest#attributes) was executed single threaded.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 3. With Servlet 3.0 the same ServletRequest#attributes is available for<br>
&gt;&gt; &gt;&gt; access from multiple threads via  ServletRequest#startAsync(), so containing<br>
&gt;&gt; &gt;&gt; objects may have a need for synchronization.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 4. Why does CDI 2.0 has to care about thread safety of @RequestScoped<br>
&gt;&gt; &gt;&gt; beans? If the application is for some reason setting the request in async<br>
&gt;&gt; &gt;&gt; mode, the application must also ensure, it&#39;s containing and accessed beans<br>
&gt;&gt; &gt;&gt; are thread safe.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Best regards<br>
&gt;&gt; &gt;&gt; Sven<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 2015-02-19 11:22 GMT+01:00 Romain Manni-Bucau &lt;<a href="mailto:rmannibucau@gmail.com">rmannibucau@gmail.com</a>&gt;:<br>
&gt;&gt; &gt;&gt; Hi<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I&#39;m +1 for it but it needs important changes (= surely new contexts).<br>
&gt;&gt; &gt;&gt; Typically we can&#39;t change today @RequestScoped (which has no link with<br>
&gt;&gt; &gt;&gt; a request but only with a thread!).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; So we could have @RequestScoped (~ @ThreadLocalScoped) and<br>
&gt;&gt; &gt;&gt; @InheritedRequestScoped which would be a real request scope (but not<br>
&gt;&gt; &gt;&gt; an InheritedThreadLocal please)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; For the request it makes a lot of sense since you need to stay thread<br>
&gt;&gt; &gt;&gt; safe even accross threads (servlet spec) and avoids to be forced to<br>
&gt;&gt; &gt;&gt; use message passing which - even if a good pattern - adds boilerplate<br>
&gt;&gt; &gt;&gt; code for simple async needs.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; For JAXRS I dont know since it is really suspend/resume semantic so<br>
&gt;&gt; &gt;&gt; request scope maybe doesnt makes much sense here (there is a break in<br>
&gt;&gt; &gt;&gt; the flow).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Romain Manni-Bucau<br>
&gt;&gt; &gt;&gt; @rmannibucau<br>
&gt;&gt; &gt;&gt; <a href="http://www.tomitribe.com" target="_blank">http://www.tomitribe.com</a><br>
&gt;&gt; &gt;&gt; <a href="http://rmannibucau.wordpress.com" target="_blank">http://rmannibucau.wordpress.com</a><br>
&gt;&gt; &gt;&gt; <a href="https://github.com/rmannibucau" target="_blank">https://github.com/rmannibucau</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; 2015-02-19 10:32 GMT+01:00 Antoine Sabot-Durand<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:antoine@sabot-durand.net">antoine@sabot-durand.net</a>&gt;:<br>
&gt;&gt; &gt;&gt; &gt; Hi All,<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Beyond the asynchronous event case, shouldn’t we provide a way for<br>
&gt;&gt; &gt;&gt; &gt; user to launch async treatments in CDI with the possibility to keep the<br>
&gt;&gt; &gt;&gt; &gt; existing contexts at the moment of async operation launch?<br>
&gt;&gt; &gt;&gt; &gt; Today servlet or JAX-RS spec support async call without the loss of<br>
&gt;&gt; &gt;&gt; &gt; request for instance. Shouldn’t we think to something like that?<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thanks for your input on that point.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Antoine<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; &gt; cdi-dev mailing list<br>
&gt;&gt; &gt;&gt; &gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Note that for all code provided on this list, the provider licenses<br>
&gt;&gt; &gt;&gt; &gt; the code under the Apache License, Version 2<br>
&gt;&gt; &gt;&gt; &gt; (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
&gt;&gt; &gt;&gt; &gt; provided on this list, the provider waives all patent and other intellectual<br>
&gt;&gt; &gt;&gt; &gt; property rights inherent in such information.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; cdi-dev mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Note that for all code provided on this list, the provider licenses the<br>
&gt;&gt; &gt;&gt; code under the Apache License, Version 2<br>
&gt;&gt; &gt;&gt; (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
&gt;&gt; &gt;&gt; provided on this list, the provider waives all patent and other intellectual<br>
&gt;&gt; &gt;&gt; property rights inherent in such information.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; cdi-dev mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Note that for all code provided on this list, the provider licenses the<br>
&gt;&gt; &gt;&gt; code under the Apache License, Version 2<br>
&gt;&gt; &gt;&gt; (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
&gt;&gt; &gt;&gt; provided on this list, the provider waives all patent and other intellectual<br>
&gt;&gt; &gt;&gt; property rights inherent in such information.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; cdi-dev mailing list<br>
&gt;&gt; &gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Note that for all code provided on this list, the provider licenses the<br>
&gt;&gt; &gt; code under the Apache License, Version 2<br>
&gt;&gt; &gt; (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
&gt;&gt; &gt; provided on this list, the provider waives all patent and other intellectual<br>
&gt;&gt; &gt; property rights inherent in such information.<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; cdi-dev mailing list<br>
&gt;&gt; <a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
&gt;&gt;<br>
&gt;&gt; Note that for all code provided on this list, the provider licenses the<br>
&gt;&gt; code under the Apache License, Version 2<br>
&gt;&gt; (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas<br>
&gt;&gt; provided on this list, the provider waives all patent and other intellectual<br>
&gt;&gt; property rights inherent in such information.<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>