Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WorkerExecutor
public class ExternalExecutor extends AbstractVerticle {
public static void main(String[] args) {
Launcher.main(new String[]{"run", ExternalExecutor.class.getName(), "-cluster"});
}
@Override
public void start() {
EventBus eb = vertx.eventBus();
eb.send("FT:test","1");
eb.send("FT:test","2");
eb.send("FT:test","3");
}
}
public class FutTest extends AbstractVerticle {
public static void main(String[] args) {
Launcher.main(new String[]{"run", FutTest.class.getName(), "-cluster"});
}
@Override
public void start() {
EventBus eb = vertx.eventBus();
WorkerExecutor executor = vertx.createSharedWorkerExecutor("my-worker-pool", 10, 200000000);
eb.consumer("FT:test", hdl-> {
executor.executeBlocking(future -> {
System.out.println("sleep: "+ hdl.body().toString());
// Call some blocking API that takes a significant amount of time to return
long startDate = System.nanoTime();
while (System.nanoTime() - startDate < 31000000000L) {
}
future.complete(true);
}, res -> {
System.out.println("The result is: " + res.result());
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.