Verwenden von asynchronen Servlets und das Verhalten der Methoden dispatch () und complete () während der Verarbeitung der Anforderung

Ich verwende asynchrone Servlets, um Anfragen zu bearbeiten,

Laut Docs :(Komplett(),Versand())

╔══════════════════╦═══════════════════════════════════════════════════════════╗
║ void complete()  ║ Completes the asynchronous operation and closes the       ║
║                  ║ response associated with this asynchronous context.       ║
║                  ║ You call this method after writing to the response object ║
║                  ║ inside the asynchronous context.                          ║ 
╠══════════════════╬═══════════════════════════════════════════════════════════╣
║ void dispatch()  ║ Dispatches the request and response objects               ║
║                  ║ of this AsyncContext to the servlet container.            ║
╚══════════════════╩═══════════════════════════════════════════════════════════╝

Ich habe es nicht verstandenasync.dispatch (), async.complete ()und wie sie funktionieren.
Ich habe einige Zweifel daran:

Was genau ist der Unterschied zwischenasync.dispatch() undasync.complete()?Wenn ich dispatch () (inside run ()) aufgerufen habe, erreicht die Antwort den Client. Bedeutet das, dass wir die Antwort asynchron senden können?wenn ich anrufeasyncContext.dispatch() zuerst undasyncContext.complete() als nächstes, wie ist das Verhalten des Threads?Wenn ich irgendeine Methode danach aufrufeasyncContext.complete(), was mit diesem Methodenaufruf geschehen wird, wie im folgenden Code gezeigt (im selbenrun())?
[Als ich das getestet habe, funktioniert es einwandfrei und zeigt die gleiche Thread-ID]Wenn ich asynchrone Methoden nach innen aufruferun() sollte ich vervollständigen müssenasyncContext.complete() InnerhalbRückrufen()? (onSuccess () oder onFailure ())

Ist eine Hilfe (Beispielquelle / Bücher / Online-Hilfe) zu diesem Thema verfügbar? (Async Servlets und Futures Kombination)

final FutureCallback<Void> calculateTime= new CustomFuture<>(calculate);
 // start Async context.
 final AsyncContext asyncContext = request.startAsync();

  asyncContext.start(new Runnable() {
        @Override
        public void run() {

            MyObject object= null;
            try {   
                object= myFactory.create();
                //dispatch async context
                asyncContext.dispatch("Object Successfully Created"); 
            } catch (final IOException e1) {
                logger.error("logging error");      
            }
            asyncContext.complete(); //complete async context

            // call asynchronous method
            final ListenableFuture<Void> future = myService.doSomething();

            Futures.addCallback(future, calculateTime);
            // calling asyncContext.complete() here will work?
        }
    });

Danke im Voraus.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage