Aniket Kulkarni
Aniket Kulkarni

Reputation: 2115

Vert.x Worker Thread Blocking

I have one vert.x Standard Verticle Basically,it parses HttpRequest and prepare JsonObject then I am sending JSONObject through eventbus. In Another Worker verticle that event get consumed and it will kick off execution(includes call to Penthao Data Integration Java API) it is blocking API.It took around 30 minutes to complete execution of ".kjb" file. But vert.x is continuously warning about Worker Thread Block so my question is what would be best practice in vert.x to tackle this scenario. Any help would be highly appreciated.

Upvotes: 3

Views: 3876

Answers (2)

Psyx
Psyx

Reputation: 778

You could also deploy your verticle as a worker.

This way:

vertx.deployVerticle(yourVerticleInstance, new DeploymentOptions().setWorker(true));

Upvotes: 2

Eugene Kirin
Eugene Kirin

Reputation: 578

According to vertx doc all blocking operations need to perform in code

vertx.executeBlocking(future -> {
  // Call some blocking API that takes a significant amount of time to return
  String result = someAPI.blockingMethod("hello");
  future.complete(result);
}, res -> {
  System.out.println("The result is: " + res.result());
});

So it's the best practice for all blocking tasks.

Upvotes: 4

Related Questions