@@ -46,11 +46,10 @@ final class AsyncServletOutputStreamWriter {
4646
4747 private final Lock writeLock = new ReentrantLock ();
4848 /**
49- * New write actions will be buffered into this queue if the servlet output stream is not ready
50- * or the queue is not drained.
49+ * New write actions will be buffered into this queue.
5150 */
5251 // SPSC queue would do
53- private final Queue <ActionItem > writeChain = new ConcurrentLinkedQueue <>();
52+ private final Queue <ActionItem > writeQueue = new ConcurrentLinkedQueue <>();
5453
5554 AsyncServletOutputStreamWriter (
5655 AsyncContext asyncContext ,
@@ -154,7 +153,8 @@ void onWritePossible() throws IOException {
154153 } finally {
155154 writeLock .unlock ();
156155 }
157- } while (!writeChain .isEmpty ());
156+ // retry if runOrBuffer added tasks to the queue, but have not acquired the lock
157+ } while (!writeQueue .isEmpty ());
158158 log .finest ("onWritePossible: EXIT. Queue drained" );
159159 }
160160
@@ -165,7 +165,7 @@ private enum WriteResult {
165165
166166 private WriteResult writeFromQueue () throws IOException {
167167 while (isReady .getAsBoolean ()) {
168- ActionItem actionItem = writeChain .poll ();
168+ ActionItem actionItem = writeQueue .poll ();
169169 if (actionItem == null ) {
170170 return WriteResult .QUEUE_DRAINED ;
171171 }
@@ -181,7 +181,7 @@ private WriteResult writeFromQueue() throws IOException {
181181 * <p>Called from application thread.
182182 */
183183 private void runOrBuffer (ActionItem actionItem ) throws IOException {
184- writeChain .offer (actionItem );
184+ writeQueue .offer (actionItem );
185185 if (writeLock .tryLock ()) { // write to the outputStream directly
186186 try {
187187 writeFromQueue ();
0 commit comments