<div dir="ltr">Wow! Thanks for the super-fast reply.<div><br></div><div>I think I&#39;m a little confused about the difference between being in an IO thread and being dispatched. Is it the case that if the server thinks I&#39;m &quot;not dispatched&quot; (that is, if the server will send a response on my behalf when my method returns) that I&#39;m always on an IO thread? I often do some work on my own thread pools and those threads often interact with the HttpServerExchange object. I know that some interactions with the exchange object (e.g. recieveFullBytes) will take an exchange that is in a dispatched state and put it in a non-dispatched state. So I want to just keep checking that I&#39;m dispatched and, if I&#39;m not, dispatch again. So my code might look something like:</div><div><br></div><div>void handle(HttpServerExchange exchange) {</div><div>    exchange.dispatch(myOwnThreadPoolExecutor, () -&gt; {</div><div>        <a href="http://log.info">log.info</a>(&quot;I am not not on an IO thread and I am dispatched.&quot;);</div><div>        doSomethingWithExchange(exchange);</div><div>        assert exchange.isDispatched();</div><div>        assert !exchange.isInIoThread();</div><div>        // how do I check to see if I&#39;m still in a dispatched state?</div><div>    });</div><div>}</div><div><br></div><div>(note: the above is a bad, super-simplified example and in the actual code there&#39;s a lot of asynchronous stuff happening that bounces the execution from one thread pool to another).</div><div><br></div><div>The reason for all of this is that I have some edge cases which appear to be race conditions in which I know for sure that I call exchange.dispatch() and then I start doing some work but the exchange gets ended before I&#39;ve finished my computations and have a response to send leaving the client with an empty response. I&#39;m not entirely sure how that could happen, but my best guess right now is that I interact with the exchange in some way that causes it to no longer be in in the dispatched state and, as a result, the HttpServerExchange is ending the exchange for me before I&#39;m ready.</div><div><br></div><div>Thanks again,<br>Oliver</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 22, 2016 at 12:47 PM Stuart Douglas &lt;<a href="mailto:sdouglas@redhat.com">sdouglas@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">After the call stack returns and the dispatch actually happens<br class="gmail_msg">
isDispatched() will return false (allowing the exchange to be<br class="gmail_msg">
dispatched again).<br class="gmail_msg">
<br class="gmail_msg">
In general you should not really need to check this anyway, if you<br class="gmail_msg">
want to know if you are in the IO thread you should use isInIiThread()<br class="gmail_msg">
instead.<br class="gmail_msg">
<br class="gmail_msg">
Stuart<br class="gmail_msg">
<br class="gmail_msg">
On Wed, Nov 23, 2016 at 7:44 AM, Oliver Dain &lt;<a href="mailto:oliver@analyticspot.com" class="gmail_msg" target="_blank">oliver@analyticspot.com</a>&gt; wrote:<br class="gmail_msg">
&gt; I&#39;ve got some pretty simple code that looks something like:<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; if (!exhange.isDispatched()) {<br class="gmail_msg">
&gt;     exchange.dispatch(() -&gt; {<br class="gmail_msg">
&gt;         assert exchange.isDispatched();<br class="gmail_msg">
&gt;          // more stuff....<br class="gmail_msg">
&gt;     });<br class="gmail_msg">
&gt; }<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; but the assert fails. That is, when dispatch calls my runnable isDispatched<br class="gmail_msg">
&gt; is not true.<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; I believe I have a bug somewhere with how/when dispatches are happening so<br class="gmail_msg">
&gt; I&#39;ve littered my code with such asserts and they fail reliably even when I&#39;m<br class="gmail_msg">
&gt; quite sure the exchange has been dispatched (e.g. when it is literally the<br class="gmail_msg">
&gt; first call in a Runnable passed to to the dispatch() method).<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; What am I doing wrong?<br class="gmail_msg">
&gt; --<br class="gmail_msg">
&gt; CTO, Analytic Spot<br class="gmail_msg">
&gt; 44 West Broadway #222<br class="gmail_msg">
&gt; Eugene, OR 97401<br class="gmail_msg">
&gt; <a href="http://analyticspot.com" rel="noreferrer" class="gmail_msg" target="_blank">analyticspot.com</a> • <a href="tel:(425)%20296-6556" value="+14252966556" class="gmail_msg" target="_blank">425-296-6556</a><br class="gmail_msg">
&gt; <a href="http://www.linkedin.com/in/oliverdain" rel="noreferrer" class="gmail_msg" target="_blank">www.linkedin.com/in/oliverdain</a><br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; _______________________________________________<br class="gmail_msg">
&gt; undertow-dev mailing list<br class="gmail_msg">
&gt; <a href="mailto:undertow-dev@lists.jboss.org" class="gmail_msg" target="_blank">undertow-dev@lists.jboss.org</a><br class="gmail_msg">
&gt; <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br class="gmail_msg">
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div style="font-size:small"><div style="font-size:13px;line-height:19.5px">CTO, Analytic Spot</div><div style="font-size:13px;line-height:19.5px">44 West Broadway #222</div><div style="font-size:13px;line-height:19.5px">Eugene, OR 97401<br></div><div style="font-size:13px;line-height:19.5px"><a href="http://analyticspot.com/" style="z-index: 0;">analyticspot.com</a> <span style="color:rgb(127,127,127);font-family:&#39;helvetica neue&#39;;font-size:11px;line-height:normal">• </span>425-296-6556</div></div><div style="font-size:small"><span style="line-height:19.5px"><a href="http://www.linkedin.com/in/oliverdain" style="z-index: 0;">www.linkedin.com/in/oliverdain</a></span></div></div></div>