Vert.x - Blocking Code

Java Conceptuel Diagram


This page is about blocking code in Vert.x that will block the event loop.

By default, blocking code is executed on the Vert.x worker pool.

How to

executing block of code in sequence

promise can be composed, the database start first, then the web server.

public void start(Promise<Void> promise) throws Exception {
	Future<Void> steps =
	  .compose(v -> startHttpServer());

wait asynchronous execution in test

public void testRemoteInfo(TestContext context) {
	Async async = context.async();

	// async test code 


execute blocking code


All the plugin of vertx are asynchronous but when starting an application you may want to stay on the main thread and to wait for an execution. You want to perform the operations in sequence.


  • when you read a configuration with configRetriever
  • and that you want to integrate it in the lifecycle hooks of the launcher, you need to retrieve the configuration before deploying a verticle.


System.out.println("Waiting for single event");
long tid = awaitEvent(h -> vertx.setTimer(1000, h));
System.out.println("Single event has fired");


To not block the main thread with blocking code such as a remote call (JDBC,…), you can use the executeBlocking function

Example from vert-x3/vertx-examples/blob/master/core-examples/src/main/java/io/vertx/example/core/execblocking/

vertx.<String>executeBlocking(future -> {

	// Do the blocking operation in here

	// Imagine this was a call to a blocking API to get the result
	try {
	} catch (Exception ignore) {
	String result = "armadillos!";


}, res -> {

	if (res.succeeded()) {


	} else {

Discover More
Java Conceptuel Diagram
Vert.x - Worker

A worker verticles is a verticle that is used to run blocking code. A worker verticle is not created from the pool of standard verticle and therefore will not block any event loops. Verticle DeploymentOptions...
Java Conceptuel Diagram
Vertx - File

This is a blocking operation

Share this page:
Follow us:
Task Runner