How to implement AsyncListener / ReadListener / WriteListener.onError in an asynchronous servlet?

The Servlet 3.1 API defines the asynchronous servlet API, which boils down to implementing the AsyncListener, WriteListener, and ReadListener interfaces. They all have an onError callback, but I cannot find useful information about the errors and expected behavior for this callback.

In the example, the author completes the AsyncContext in onError callbacks:

public void onError(final Throwable t) {
    ac.complete();
    t.printStackTrace();
}

Is there any best practice as to what sergeant async should do in case of an error?

Interestingly, onError handlers do not raise if an HTTP request is interrupted by the client (tested with Jetty 9.1.3). However, in this case, there seems to be a memory leak, since WriteListener does not seem to be cleared. Only instances of ReadListener and AsyncListener see the finalize () call when System.gc () is called (for testing).

+4
source share

Source: https://habr.com/ru/post/1532678/


All Articles