From e4eb21352f8cea36db99458a08675559a11f88fa Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Wed, 21 Sep 2016 15:27:09 +0200 Subject: [PATCH] Context#executeBlocking does not log blocked threads - fixes #1633 --- .../java/io/vertx/core/impl/ContextImpl.java | 8 +++++ .../test/core/BlockedThreadCheckerTest.java | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/vertx/core/impl/ContextImpl.java b/src/main/java/io/vertx/core/impl/ContextImpl.java index 7669cf674ed..2ef4dd04a9e 100644 --- a/src/main/java/io/vertx/core/impl/ContextImpl.java +++ b/src/main/java/io/vertx/core/impl/ContextImpl.java @@ -248,10 +248,14 @@ void executeBlocking(Action action, Handler> blockingCodeHandle Object queueMetric = metrics != null ? metrics.submitted() : null; try { exec.execute(() -> { + VertxThread current = (VertxThread) Thread.currentThread(); Object execMetric = null; if (metrics != null) { execMetric = metrics.begin(queueMetric); } + if (!DISABLE_TIMINGS) { + current.executeStart(); + } Future res = Future.future(); try { if (blockingCodeHandler != null) { @@ -263,6 +267,10 @@ void executeBlocking(Action action, Handler> blockingCodeHandle } } catch (Throwable e) { res.fail(e); + } finally { + if (!DISABLE_TIMINGS) { + current.executeEnd(); + } } if (metrics != null) { metrics.end(execMetric, res.succeeded()); diff --git a/src/test/java/io/vertx/test/core/BlockedThreadCheckerTest.java b/src/test/java/io/vertx/test/core/BlockedThreadCheckerTest.java index 42e21b69f73..a886131de2a 100644 --- a/src/test/java/io/vertx/test/core/BlockedThreadCheckerTest.java +++ b/src/test/java/io/vertx/test/core/BlockedThreadCheckerTest.java @@ -61,9 +61,33 @@ public void start() throws InterruptedException { vertxOptions.setMaxWorkerExecuteTime(1000000000); vertxOptions.setWarningExceptionTime(1000000000); Vertx newVertx = vertx(vertxOptions); - DeploymentOptions depolymentOptions = new DeploymentOptions(); - depolymentOptions.setWorker(true); - newVertx.deployVerticle(verticle, depolymentOptions); + DeploymentOptions deploymentOptions = new DeploymentOptions(); + deploymentOptions.setWorker(true); + newVertx.deployVerticle(verticle, deploymentOptions); + await(); + } + + @Test + public void testBlockCheckExecuteBlocking() throws Exception { + Verticle verticle = new AbstractVerticle() { + @Override + public void start() throws InterruptedException { + vertx.executeBlocking(fut -> { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + fail(); + } + testComplete(); + }, ar -> {}); + } + }; + // set warning threshold to 1s and the exception threshold as well + VertxOptions vertxOptions = new VertxOptions(); + vertxOptions.setMaxWorkerExecuteTime(1000000000); + vertxOptions.setWarningExceptionTime(1000000000); + Vertx newVertx = vertx(vertxOptions); + newVertx.deployVerticle(verticle); await(); } }