Package com.github.mizool.core
Class Interval
- java.lang.Object
-
- com.github.mizool.core.Interval
-
@ThreadSafe public class Interval extends Object
Helper class to allow for something to happen at regular intervals. A common use case might be invalidation of in-memory data.
Example to invalidate a cache every minute:private final Interval cacheInvalidationInterval = new Interval(Duration.ofMinutes(1)); ... cacheInvalidationInterval.runIfDue(this::invalidateCache);
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
runIfDue(Runnable runnable)
Executes therunnable
if the interval is due or past due.
-
-
-
Constructor Detail
-
Interval
public Interval(Duration duration)
-
-
Method Detail
-
runIfDue
public boolean runIfDue(Runnable runnable)
Executes therunnable
if the interval is due or past due. The next full interval is started after completion of the runnable.- Returns:
true
if the operation was due and the runnable completed.
-
-