diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a1a74e..a9d9ed98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ## Release Notes +`1.1.4` + +- Added `Threads.safeJoin(Thread, Duration)` to join a thread with a timeout, with `InterruptedException` handling. +- Fixed `ReschedulingTask.enable()` to throw `IllegalStateException` after the task has been closed. +- Changed `ReschedulingTask.close()` to mark the task permanently closed before cleaning up resources. +- Fixed `ReschedulingTask.disable()` to preserve a concurrent enable while cancellation finishes. +- Added `ReschedulingTask.isNotScheduled()` to report whether there is no pending scheduled execution. + +--- + `1.1.3` - Added `ExtendedField.valueNotNull()` to check whether the field value is not `null`, usable as a predicate for `ExtendedFields.findAllNonStatic`. diff --git a/README.md b/README.md index 3de9bb15..9e76dc69 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ A library that exposes general Java utility and reflection methods and a package ### Releases -Current release `1.1.3` +Current release `1.1.4` ### Documentation @@ -88,6 +88,6 @@ Maven: add this dependency to your `pom.xml` io.github.raduking morphix-all - 1.1.3 + 1.1.4 ``` diff --git a/pom.xml b/pom.xml index 4c2cdaff..a1534c10 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ io.github.raduking morphix-all - 1.1.3 + 1.1.4 jar ${project.groupId}:${project.artifactId} diff --git a/src/main/java/org/morphix/lang/thread/ReschedulingTask.java b/src/main/java/org/morphix/lang/thread/ReschedulingTask.java index 76718b50..a540dcdf 100644 --- a/src/main/java/org/morphix/lang/thread/ReschedulingTask.java +++ b/src/main/java/org/morphix/lang/thread/ReschedulingTask.java @@ -20,7 +20,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; @@ -46,15 +45,37 @@ * any future executions and cancel any currently scheduled task. The task also provides a close method to clean up * resources when it is no longer needed. *

- * Useful for token refreshers, cache refreshers, heartbeat mechanisms, etc. - *

+ * Whether the task is enabled and whether a scheduler future is still pending are separate concerns. The task may be + * enabled with no pending future while the initial refresh runs on the thread that called {@link #enable()}, or after a + * scheduled run has finished and the tracked future reference has been cleared. + *

+ * Useful for token refreshers, cache refreshers, heart-beat mechanisms, etc. * * @author Radu Sebastian LAZIN */ public class ReschedulingTask implements AutoCloseable { + /** + * Lifecycle states. A closed task cannot be enabled again. + */ + private enum State { + + /** + * The task is inactive and can be enabled. + */ + DISABLED, + + /** + * The task is active and can execute and reschedule itself. Does not imply a pending scheduled future. + */ + ENABLED, + + /** + * The task is permanently inactive and cannot be enabled again. + */ + CLOSED + } + /** * Name space class for default values. Other defaults which are not constants: *