Skip to content

Instantly share code, notes, and snippets.

@jojopad
Last active July 5, 2017 04:32
Show Gist options
  • Save jojopad/6f21565c9999718cf2479c025725b471 to your computer and use it in GitHub Desktop.
Save jojopad/6f21565c9999718cf2479c025725b471 to your computer and use it in GitHub Desktop.
/**
To run:
1. Install Groovy using sdkman (http://sdkman.io)
2. Excecute script using groovy command:
groovy -Dgroovy.grape.report.downloads=true SharedWorkerExecutorSample.groovy
*/
// @Grab('io.vertx:vertx-core:3.3.3')
@Grab('io.vertx:vertx-core:3.4.0')
// @Grab('io.vertx:vertx-core:3.4.1')
// @Grab('io.vertx:vertx-core:3.4.2')
import io.vertx.core.*
Vertx.vertx().deployVerticle(new AbstractVerticle() {
@Override
void start() throws Exception {
def worker1 = vertx.createSharedWorkerExecutor('WORKER-1')
def worker2 = vertx.createSharedWorkerExecutor('WORKER-2')
def worker3 = vertx.createSharedWorkerExecutor('WORKER-3')
def printThread = {
def ctr = 0
while (true) {
println "${Thread.currentThread().name} ${++ctr} sec"
Thread.sleep(1_000)
}
}
worker1.executeBlocking({ future ->
printThread()
future.complete()
}, {
// Do nothing.
})
worker2.executeBlocking({ future ->
printThread()
future.complete()
}, {
// Do nothing.
})
worker3.executeBlocking({ future ->
printThread()
future.complete()
}, {
// Do nothing.
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment