From 52b09474baab5459f22cd435d6a3098cefaaf559 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sat, 12 Dec 2020 22:30:40 +0100 Subject: [PATCH] Add documentation --- .../executor/ScheduledTaskLifecycle.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/org/warp/commonutils/concurrency/executor/ScheduledTaskLifecycle.java b/src/main/java/org/warp/commonutils/concurrency/executor/ScheduledTaskLifecycle.java index a6189c3..3cd9ef0 100644 --- a/src/main/java/org/warp/commonutils/concurrency/executor/ScheduledTaskLifecycle.java +++ b/src/main/java/org/warp/commonutils/concurrency/executor/ScheduledTaskLifecycle.java @@ -15,23 +15,37 @@ public class ScheduledTaskLifecycle { this.lock = new StampedLock(); } + /** + * Register a scheduled task + */ public void registerScheduledTask(ScheduledFuture task) { this.tasks.put(task, new Object()); } + /** + * Mark this task as running. + * After calling this method, please call {@method endScheduledTask} inside a finally block! + */ public void startScheduledTask() { this.lock.readLock(); } + /** + * Mark this task as ended. Must be called after {@method startScheduledTask} + */ public void endScheduledTask() { this.lock.tryUnlockRead(); } + /** + * Cancel all scheduled tasks and wait all running methods to finish + */ public void cancelAndWait() { tasks.forEach((task, obj) -> { task.cancel(false); }); + // Acquire a write lock to wait all tasks to end lock.unlockWrite(lock.writeLock()); } }