This is my first try to do a asynchronous program with java.
My requirement is that whenever I receive a request I have to start a task which may take an hour. Therefore I have immediately reply to the user that “ the task has started” before the task finishes. I amusing apache timcat version 8.5.23.
I assumed that AsyncContext.start()
will help me but what I found that AsyncContext won’t return the response to the client until it calls the onComplete(AsyncEvent event)
.
Is there a way I can respond to the user before onComplete(AsyncEvent event)
happens?
I did see a similar question How to execute code after response in JavaEE .
I heard that https://vertx.io/docs/guide-for-java-devs/ may help me but before diving into deep; I am wondering, is there any other better way or technology to do this?
Thanks in advance.
Instead of using
AsyncContext.start(Runnable)
, I usedCompletableFuture.runAsync(Runnable)
and it worked as expected.