Last active
July 3, 2017 02:00
-
-
Save jojopad/6bff17173039ee1e95a6685172925c56 to your computer and use it in GitHub Desktop.
Groovy script for testing Vertx BlockedThreadChecker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Groovy script for testing Vertx BlockedThreadChecker. | |
To run: | |
1. Install Groovy using sdkman (http://sdkman.io) | |
2. Excecute script using groovy command: | |
groovy -Dgroovy.grape.report.downloads=true BlockedThreadCheckerTest.groovy | |
*/ | |
@Grab('io.vertx:vertx-core:3.4.2') | |
import io.vertx.core.* | |
def options = new VertxOptions() | |
// The ff line will cause the BlockedThreadChecker warning log to show immediately after | |
// executing the blocking code, with time limit shown as 0 (which is incorrect). | |
// The BlockedThreadChecker works fine with the default 60s time limit value after removing the ff line. | |
options.setMaxWorkerExecuteTime(10_000) // time unit is in nanoseconds in vertx 3.4 (previously in milliseconds in 3.3) | |
def vertx = Vertx.vertx(options) | |
vertx.deployVerticle(new AbstractVerticle() { | |
def executor = vertx.createSharedWorkerExecutor('shared-exec', 10) | |
@Override | |
void start() throws Exception { | |
executor.executeBlocking({ future -> | |
def ctr = 0 | |
while (true) { | |
println "${++ctr} sec" | |
Thread.sleep(1_000) | |
} | |
future.complete() | |
}, { | |
// Do nothing. | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment