Package dev.brachtendorf.concurrency
Class DelayedConsumerHashMap<T>
- java.lang.Object
-
- dev.brachtendorf.concurrency.DelayedConsumerHashMap<T>
-
- Type Parameters:
T- Type of the task the consumer will execute
public class DelayedConsumerHashMap<T> extends Object
Accepts a consumer which executes all provided tasks in a batch no more often than the delay specified. Tasks are labeled by id and will replace each other if they arrive within the grace period while ensuring that the task scheduled last will eventually be executed.- Event( key = 1) arrives. Consumer has not executed a task therefore it is executed immediately.
- Event( key = 2) arrives. Consumer is currently sleeping
- Event( key = 1) arrives. Consumer is currently sleeping
- Event( key = 2) arrives. Consumer is currently sleeping. The first event with key 2 is replaced and will never be executed.
- Grace period over. Execute Event(key = 2) and Event( key = 1)
- Lay dormant until new tasks arrive
- Since:
- 1.0.0 com.github.kilianB
- Author:
- Kilian
-
-
Constructor Summary
Constructors Constructor Description DelayedConsumerHashMap(Consumer<T> consumer, int sleep)
-