Skip to content

Commit 5a95530

Browse files
committed
feat: add DelayQueueDemo showcasing delayed task execution with DelayQueue
Implemented DelayQueueDemo.java to demonstrate scheduling tasks using DelayQueue, a thread-safe unbounded blocking queue. Illustrates how elements become available only after their delay expires via DelayedTask implementation using getDelay() and compareTo() for time-based ordering. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 43bbbb6 commit 5a95530

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Section 25 Collections Frameworks/Queue Interface/Delay Queue/src/DelayQueueDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void main(String[] args) throws InterruptedException {
99
// Elements can only be taken from the queue when their delay has expired
1010
// Useful for scheduling tasks to be executed after a certain delay
1111
// internally priority queue
12+
1213
BlockingQueue<DelayedTask> delayQueue = new DelayQueue<>();
1314
delayQueue.put(new DelayedTask("Task1", 5, TimeUnit.SECONDS));
1415
delayQueue.put(new DelayedTask("Task2", 3, TimeUnit.SECONDS));
@@ -22,7 +23,6 @@ public static void main(String[] args) throws InterruptedException {
2223
}
2324

2425
class DelayedTask implements Delayed {
25-
2626
private final String taskName;
2727
private final long startTime;
2828

@@ -51,4 +51,4 @@ public int compareTo(Delayed o) {
5151
public String getTaskName() {
5252
return taskName;
5353
}
54-
}
54+
}

0 commit comments

Comments
 (0)