Skip to content

Instantly share code, notes, and snippets.

@ivanovdns
Created October 6, 2016 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanovdns/c2abfb99df10deee022b0ef8318f3610 to your computer and use it in GitHub Desktop.
Save ivanovdns/c2abfb99df10deee022b0ef8318f3610 to your computer and use it in GitHub Desktop.
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