<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, Nov 2, 2018 at 1:25 AM Martin Kouba &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The spec is very clear that this should be possible. See for example <br>
6.5.1. The active context object for a scope:<br>
&quot;The container must search for an active instance of Context associated <br>
with the scope type.&quot;<br></blockquote><div><br></div><div>Not so sure about the &quot;very clear&quot; part :-) but yes, you can read it this way and clearly that&#39;s the intent so that&#39;s good enough for me!</div><div><br></div><div>Follow-up question: a <font face="monospace">Context</font>&#39;s &quot;activeness&quot; is defined per-thread (<a href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#context">section 6.2</a>):</div><div><br></div><div>&quot;At a particular point in the execution of the program a context object may be active with respect to the current thread.&quot;</div><div><br></div><div>So when I ask the <font face="monospace">BeanManager</font> for the (singular) <font face="monospace">Context</font>-that-is-active-with-respect-to-the-current-thread by giving it a scope annotation, I get back a <font face="monospace">Context</font> whose <font face="monospace">isActive()</font> method returned <font face="monospace">true</font> at some point during the implementation of the <a href="http://docs.jboss.org/cdi/api/2.0/javax/enterprise/inject/spi/BeanManager.html#getContext-java.lang.Class-"><font face="monospace">BeanManager#getContext(Class)</font> method</a>.  And certainly I&#39;d hope that once I receive this <font face="monospace">Context</font> its <font face="monospace">isActive()</font> method would return <font face="monospace">true</font>.</div><div><br></div><div>But this is just a &quot;best effort&quot; area of the specification, right?</div><div><br></div><div>Consider a (hypothetical, thought-experiment) stupid <font face="monospace">Context</font> that tracks whether it&#39;s active or not for a given <font face="monospace">Thread</font> (using a <font face="monospace">Map</font> of <font face="monospace">Thread</font>s-to-<font face="monospace">boolean</font>s or something similar).  Then pretend solely for discussion purposes that it has a daemon <font face="monospace">Thread</font> in it that randomly and periodically sets its activeness to <font face="monospace">true</font> or <font face="monospace">false</font> for a given <font face="monospace">Thread</font>.  So sometimes a caller of its <font face="monospace">isActive()</font> method gets <font face="monospace">true</font> back, and sometimes it gets <font face="monospace">false</font> based on the random activeness-toggling actions of the internal daemon thread.  Again, this is a thought experiment, not proposed or useful code.  :-)</div><div><br></div><div>All the <font face="monospace">BeanManager</font> can do in this (stupid but legal?) case is make a <i>best effort</i>: at the time it selects the <font face="monospace">Context</font> for returning from its <font face="monospace">getContext(Class)</font> method, the <font face="monospace">Context</font> must have returned <font face="monospace">true</font> from its <font face="monospace">isActive()</font> method (otherwise it would not be a candidate for returning), but the caller of <font face="monospace">BeanManager#getContext(Class)</font> receiving this stupid <font face="monospace">Context</font> may invoke <font face="monospace">isActive()</font> and discover that suddenly it is returning <font face="monospace">false</font> because of the actions of its stupid embedded daemon thread.  Is this thought-experiment scenario correct and permitted by the laws of the specification?</div><div><br></div><div>Another way to ask this: is the following statement true or false?  I believe it is true:</div><div><br></div><div>    There is no requirement that the activeness of a <font face="monospace">BeanManager</font>-vended <font face="monospace">Context</font> be immutable with respect to the calling thread.</div><div><br></div><div>(It seems this statement must be true or the fact that a <font face="monospace">Context</font> can throw <font face="monospace">ContextNotActiveException</font> from its methods would seemingly make no sense.)</div><div><br></div><div>I&#39;m just trying to understand this area very deeply, particularly with respect to threading.  Thanks as always for your time.</div><div><br></div><div>Best,</div><div>Laird</div></div></div>