You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/09/05 14:26:05 UTC
svn commit: r1759278 -
/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java
Author: bdelacretaz
Date: Mon Sep 5 14:26:05 2016
New Revision: 1759278
URL: http://svn.apache.org/viewvc?rev=1759278&view=rev
Log:
SLING-5874 - avoid wasting 50ms in HealthCheckExecutorImpl - contributed by Georg Henzler, thanks!
Modified:
sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java
Modified: sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java?rev=1759278&r1=1759277&r2=1759278&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/core/src/main/java/org/apache/sling/hc/core/impl/executor/HealthCheckExecutorImpl.java Mon Sep 5 14:26:05 2016
@@ -340,8 +340,22 @@ public class HealthCheckExecutorImpl imp
}
});
this.stillRunningFutures.put(metadata, future);
-
- this.hcThreadPool.execute(future);
+
+ final HealthCheckFuture newFuture = future;
+ this.hcThreadPool.execute(new Runnable() {
+ @Override
+ public void run() {
+ newFuture.run();
+ synchronized ( stillRunningFutures ) {
+ // notify executor threads that newFuture is finished. Wrapping it in another runnable
+ // ensures that newFuture.isDone() will return true (if e.g. done in callback above, there are
+ // still a few lines of code until the future is really done and hence then the executor thread
+ // is sometime notified a bit too early, still receives the result isDone()=false and then waits
+ // for another 50ms, even though the future was about to be done one ms later)
+ stillRunningFutures.notifyAll();
+ }
+ }
+ });
}
return future;
@@ -359,10 +373,16 @@ public class HealthCheckExecutorImpl imp
if (options != null && options.getOverrideGlobalTimeout() > 0) {
effectiveTimeout = options.getOverrideGlobalTimeout();
}
+
+ if(futuresForResultOfThisCall.isEmpty()) {
+ return; // nothing to wait for (usually because of cached results)
+ }
do {
try {
- Thread.sleep(50);
+ synchronized (stillRunningFutures) {
+ stillRunningFutures.wait(50); // wait for notifications of callbacks of HealthCheckFutures
+ }
} catch (final InterruptedException ie) {
logger.warn("Unexpected InterruptedException while waiting for healthCheckContributors", ie);
}