I've looked at your reproducer and have run it. Your expectations are simply incorrect.
Here is the code flow in your reproducer:
In this flow, your sendRedirect(...) happens before the System.out calls. Thus the System.out from RedirectionTarget will happen in parallel with the the System.out calls in your RedirectionSource.doPost(...) method.
Be advised that my expectation are correct when running the provided project under Apache Tomcat, WebLogic and WebSphere.
Kindly try to run it under tomcat and check the output. is it possible that there's a Wildfly configuration to be applied in order to meet the expectation?
Thanks and Best Regards
I refer you to section 5.5 of the servlet specification:
"[sendRedirect(...)] will have the side effect of committing the response, if it has not already been committed, and terminating it. No further output to the client should be made by the servlet after these methods are called. If data is written to the response after these methods are called, the data is ignored."
Therefore, following the sendRedirect(...) invocation, the client that initiated the request will receive a 302 response, sending another request to the redirection target. This second auto-initiated request might be processed by the same thread (if the previous thread has already completed), or it might happen in a second thread. This behavior is can vary between servlet container implementations. If there is logic that should execute before the redirected request is processed, then you should execute this logic before you call sendRedirect(...).