Package com.github.mizool.core
Class Interval
java.lang.Object
com.github.mizool.core.Interval
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:
Example to invalidate a cache every minute:
private final Interval cacheInvalidationInterval = new Interval(Duration.ofMinutes(1));
...
cacheInvalidationInterval.runIfDue(this::invalidateCache);
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Interval
-
-
Method Details
-
runIfDue
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.
-