Let's say I write pieces of data in an HttpServletResponse . So my method gets an array of bytes, I write it in response.getOutputStream() , and then free the stream. When I get another piece of data, my method will wake up and it will write getOutputStream() again. In the end, I call AsyncContext.complete() .
Now the WriteListener.onWritePossible() specification says:
this method will be called by the container the first time it is possible to write data. Then the container will refer to onWritePossible if and only if the isReady method on the ServletOutputStream described below returns false.
It seems that when the container calls this method, I already need my answer to be buffered somewhere, because onWritePossible() can never be called again. So, for the previous example, I need to write all the pieces of data that I receive in the buffer (a byte array or, possibly, a temporary file if the buffer is large enough), and if onWritePossible() is called before my answer finishes, what should I do? Block the thread until I have all my response data?
source share