jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
253 stars 81 forks source link

AsyncListener question #570

Closed jkvargas closed 6 months ago

jkvargas commented 6 months ago

when I am handling a request I am acquiring a semaphore and releasing when complete. Do I actually need to release at some other moment? Can complete not happen for some reason? consider baseRequest of type org.eclipse.jetty.server.Request and _concurrencyGate of type Semaphore.

if (_concurrencyGate.tryAcquire(...)) {
  var asyncContext = baseRequest.getAsyncContext();

  asyncContext.addListener(new AsyncListener() {
                      @Override
                      public void onComplete(AsyncEvent event) {
                          _concurrencyGate.release();
                      }

                      @Override
                      public void onTimeout(AsyncEvent event) {\
                      }

                      @Override
                      public void onError(AsyncEvent event) {
                      }

                      @Override
                      public void onStartAsync(AsyncEvent event) {}

                  }, request, response);
  }
}
markt-asf commented 6 months ago

onComplete() should be called at the end of every async cycle. If you observe otherwise, that would be something to take up with the vendor of the Servlet container you are using.