You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2016/02/24 12:03:53 UTC
svn commit: r1732072 - in /jackrabbit/oak/trunk:
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/
oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Author: davide
Date: Wed Feb 24 11:03:53 2016
New Revision: 1732072
URL: http://svn.apache.org/viewvc?rev=1732072&view=rev
Log:
OAK-4025 - Reuse ExecutorUtils to shutdown ExecutorService
got rid of ExecutorUtils in favour of reusing the ExcutorCloser
Removed:
jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorUtils.java
Modified:
jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/AtomicCounterEditorProvider.java
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AtomicCounterClusterIT.java
Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java?rev=1732072&r1=1732071&r2=1732072&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java (original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java Wed Feb 24 11:03:53 2016
@@ -29,19 +29,38 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Utility class to properly close any ExecutorService. It ensures
- * that executor is properly closed once the call from close is returned
+ * <p>
+ * Utility class to properly close any ExecutorService.
+ * </p>
+ *
+ * <p>
+ * It will attempt a graceful close within the provided timeout. If after such any of the contained
+ * tasks are not terminated yet, it will force a shutdown and track a warning in the logs.
+ * </p>
+ *
*/
public final class ExecutorCloser implements Closeable {
- private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final Logger LOG = LoggerFactory.getLogger(ExecutorCloser.class);
private final ExecutorService executorService;
private final int timeout;
private final TimeUnit timeUnit;
+ /**
+ * will attempt a graceful close in 5 seconds
+ *
+ * @param executorService
+ */
public ExecutorCloser(@Nullable ExecutorService executorService) {
this(executorService, 5, TimeUnit.SECONDS);
}
+ /**
+ * will attempt a graceful close by the provided time.
+ *
+ * @param executorService the executor to close
+ * @param timeout the time to wait for
+ * @param unit the unit of time
+ */
public ExecutorCloser(@Nullable ExecutorService executorService, int timeout, TimeUnit unit) {
this.executorService = executorService;
this.timeout = timeout;
@@ -57,13 +76,15 @@ public final class ExecutorCloser implem
executorService.shutdown();
executorService.awaitTermination(timeout, timeUnit);
} catch (InterruptedException e) {
- log.error("Error while shutting down the executorService", e);
+ LOG.error("Error while shutting down the ExecutorService", e);
Thread.currentThread().interrupt();
} finally {
- if (!executorService.isTerminated()) {
- log.warn("ExecutorService didn't shutdown properly. Will be forced now.");
+ if (!executorService.isShutdown()) {
+ LOG.warn("ExecutorService `{}` didn't shutdown property. Will be forced now.",
+ executorService);
}
executorService.shutdownNow();
}
+
}
}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/AtomicCounterEditorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/AtomicCounterEditorProvider.java?rev=1732072&r1=1732071&r2=1732072&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/AtomicCounterEditorProvider.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/atomic/AtomicCounterEditorProvider.java Wed Feb 24 11:03:53 2016
@@ -22,7 +22,6 @@ import static org.apache.felix.scr.annot
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;
@@ -36,6 +35,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.Editor;
@@ -188,17 +188,7 @@ public class AtomicCounterEditorProvider
LOG.debug("No ScheduledExecutorService found");
} else {
LOG.debug("Shutting down ScheduledExecutorService");
- try {
- ses.shutdown();
- ses.awaitTermination(5, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- LOG.error("InterruptedException white shutting down ScheduledExecutorService", e);
- } finally {
- if (!ses.isTerminated()) {
- LOG.debug("ScheduledExecutorService not yet shutdown. Cancelling tasks and forcing quit.");
- }
- ses.shutdownNow();
- }
+ new ExecutorCloser(ses).close();
}
}
Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AtomicCounterClusterIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AtomicCounterClusterIT.java?rev=1732072&r1=1732071&r2=1732072&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AtomicCounterClusterIT.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AtomicCounterClusterIT.java Wed Feb 24 11:03:53 2016
@@ -45,7 +45,7 @@ import javax.jcr.Session;
import org.apache.jackrabbit.oak.commons.FixturesHelper;
import org.apache.jackrabbit.oak.commons.FixturesHelper.Fixture;
-import org.apache.jackrabbit.oak.commons.concurrent.ExecutorUtils;
+import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
import org.apache.jackrabbit.oak.plugins.atomic.AtomicCounterEditor;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.apache.jackrabbit.oak.util.PerfLogger;
@@ -81,7 +81,7 @@ public class AtomicCounterClusterIT ext
public void after() throws Exception {
super.after();
for (CustomScheduledExecutor exec : executors) {
- ExecutorUtils.shutdownIn10s(exec);
+ new ExecutorCloser(exec, 10, TimeUnit.SECONDS).close();
}
}