Package com.yahoo.concurrent
Class StripedExecutor<Key>
java.lang.Object
com.yahoo.concurrent.StripedExecutor<Key>
Executor that serializes runnables with the same key, but may parallelize over different keys.
- Author:
- jonmv
-
Constructor Summary
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoid
Executes the given command.void
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 Details
-
StripedExecutor
public StripedExecutor()Creates a new StripedExecutor which delegates to aExecutors.newCachedThreadPool(ThreadFactory)
. -
StripedExecutor
Creates a new StripedExecutor which delegates to the given executor service.
-
-
Method Details
-
execute
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
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.
-