Vertx : Running a block of code outside of the eventloop

I write a service by Vertx. My service run a function like this :

router.get("/report").handle(ServiceHandler::Count);

My Count function takes a long time (about from 10 to 15 minutes) and that broke the golden rule of Vertx. I'm newbie and I've tried google it but I can not find the way out.

Please help me out! Thanks very much.

Upvotes: 0

Views: 599

Answers (2)

injecteer
injecteer

Reputation: 20699

If the processing should take over 1 minute, generally you should NOT make it run via router from http-request.

Your ServiceHandler::Count function should rather return immediately with a "process started" message, and use some long-running mechanism like SockJS or good-ol email to notify the user about the completion.

Upvotes: 0

tsegismont
tsegismont

Reputation: 9128

In this case use a blocking handler:

router.get("/report").blockingHandler(ServiceHandler::Count);

Note that, by default, even worker threads are monitored by the blocked thread checker. A warning for blocked workers is generated after 60 seconds.

If the processing takes several minutes, adjust setMaxWorkerExecuteTime and setMaxWorkerExecuteTimeUnit accordingly.

Upvotes: 1

Related Questions