Package com.yahoo.concurrent
Class StripedExecutor<Key>
- java.lang.Object
-
- com.yahoo.concurrent.StripedExecutor<Key>
-
public class StripedExecutor<Key> extends Object
Executor that serializes runnables with the same key, but may parallelize over different keys.- Author:
- jonmv
-
-
Constructor Summary
Constructors Constructor Description StripedExecutor()
Creates a new StripedExecutor which delegates to aExecutors.newCachedThreadPool(ThreadFactory)
.StripedExecutor(ExecutorService executor)
Creates a new StripedExecutor which delegates to the given executor service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(Key key, Runnable command)
Executes the given command.void
shutdownAndWait()
Shuts down the delegate executor and waits for it to terminate.void
shutdownAndWait(Duration grace, Duration die)
Shuts down the delegate executor and waits for the given grace duration for it to terminate.
-
-
-
Constructor Detail
-
StripedExecutor
public StripedExecutor()
Creates a new StripedExecutor which delegates to aExecutors.newCachedThreadPool(ThreadFactory)
.
-
StripedExecutor
public StripedExecutor(ExecutorService executor)
Creates a new StripedExecutor which delegates to the given executor service.
-
-
Method Detail
-
execute
public void execute(Key key, Runnable command)
Executes the given command. If other commands are already running or queued for the given key, execution of this command happens after those, on the same thread as is running them.Any exception thrown by the command will only be logged, to allow subsequent commands to run.
-
shutdownAndWait
public void shutdownAndWait()
Shuts down the delegate executor and waits for it to terminate.
-
shutdownAndWait
public void shutdownAndWait(Duration grace, Duration die)
Shuts down the delegate executor and waits for the given grace duration for it to terminate. If this fails, tells the executor toExecutorService.shutdownNow()
), and waits for the die duration.
-
-