Repository: accumulo Updated Branches: refs/heads/master 45a027c9c -> 888263236
ACCUMULO-1311 ACCUMULO-3511 Remove Daemon from fate and use ExecutorService The Daemon class was only used in a single location by FATE which is easily achieved with a ThreadFactory instead. Also changes from manually creating and starting threads to using a fixed-size executor service instead. Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f6129602 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f6129602 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f6129602 Branch: refs/heads/master Commit: f6129602ae2a88da3bd78bb7ae0479c241bc0a4f Parents: 45a027c Author: Josh Elser <els...@apache.org> Authored: Fri Jan 23 13:13:54 2015 -0500 Committer: Josh Elser <els...@apache.org> Committed: Fri Jan 23 14:43:28 2015 -0500 ---------------------------------------------------------------------- .../java/org/apache/accumulo/fate/Fate.java | 22 +++++-- .../org/apache/accumulo/fate/util/Daemon.java | 60 -------------------- 2 files changed, 18 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/f6129602/fate/src/main/java/org/apache/accumulo/fate/Fate.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/Fate.java b/fate/src/main/java/org/apache/accumulo/fate/Fate.java index f9c1ed0..aa9c456 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/Fate.java +++ b/fate/src/main/java/org/apache/accumulo/fate/Fate.java @@ -17,10 +17,13 @@ package org.apache.accumulo.fate; import java.util.EnumSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.accumulo.fate.ReadOnlyTStore.TStatus; -import org.apache.accumulo.fate.util.Daemon; import org.apache.accumulo.fate.util.LoggingRunnable; import org.apache.log4j.Logger; @@ -41,6 +44,7 @@ public class Fate<T> { private TStore<T> store; private T environment; + private ExecutorService executor; private static final EnumSet<TStatus> FINISHED_STATES = EnumSet.of(TStatus.FAILED, TStatus.SUCCESSFUL, TStatus.UNKNOWN); @@ -154,10 +158,19 @@ public class Fate<T> { * Launches the specified number of worker threads. */ public void startTransactionRunners(int numThreads) { + final AtomicInteger runnerCount = new AtomicInteger(0); + executor = Executors.newFixedThreadPool(numThreads, new ThreadFactory() { + + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(new LoggingRunnable(log, r), "Repo runner " + runnerCount.getAndIncrement()); + t.setDaemon(true); + return t; + } + + }); for (int i = 0; i < numThreads; i++) { - // TODO: use an ExecutorService, maybe a utility to do these steps throughout the server packages - ACCUMULO-1311 - Thread thread = new Daemon(new LoggingRunnable(log, new TransactionRunner()), "Repo runner " + i); - thread.start(); + executor.execute(new TransactionRunner()); } } @@ -250,6 +263,7 @@ public class Fate<T> { */ public void shutdown() { keepRunning.set(false); + executor.shutdown(); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/f6129602/fate/src/main/java/org/apache/accumulo/fate/util/Daemon.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/util/Daemon.java b/fate/src/main/java/org/apache/accumulo/fate/util/Daemon.java deleted file mode 100644 index da7c41c..0000000 --- a/fate/src/main/java/org/apache/accumulo/fate/util/Daemon.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.accumulo.fate.util; - -public class Daemon extends Thread { - - public Daemon() { - setDaemon(true); - } - - public Daemon(Runnable target) { - super(target); - setDaemon(true); - } - - public Daemon(String name) { - super(name); - setDaemon(true); - } - - public Daemon(ThreadGroup group, Runnable target) { - super(group, target); - setDaemon(true); - } - - public Daemon(ThreadGroup group, String name) { - super(group, name); - setDaemon(true); - } - - public Daemon(Runnable target, String name) { - super(target, name); - setDaemon(true); - } - - public Daemon(ThreadGroup group, Runnable target, String name) { - super(group, target, name); - setDaemon(true); - } - - public Daemon(ThreadGroup group, Runnable target, String name, long stackSize) { - super(group, target, name, stackSize); - setDaemon(true); - } - -}