Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Thread-Safe Delayed Task Runner

Model and implement an in-process one-shot scheduler whose earliest-deadline wakeups, callback execution, cancellation, and shutdown remain correct under concurrency.

For this exercise, assume callers schedule one-shot Runnable tasks with a non-negative delay. A dedicated dispatcher waits efficiently until the earliest deadline and hands due tasks to a bounded execution pool. Concurrent producers may add or cancel tasks while the dispatcher is waiting.

A newly inserted earlier deadline must wake the dispatcher; spurious wakeups and wall-clock adjustments must not run a task early; user callbacks must never execute while scheduler state is locked.

The runner invokes each admitted callback at most once after dispatch; callback exceptions are recorded as failed outcomes and are not automatically retried. Design the object model and interfaces, walk through the important races, and implement the blocking delayed-queue core used by the dispatcher.

Also define graceful and immediate shutdown behavior. Recurring schedules, rescheduling, durable process-restart recovery, distributed coordination, task priorities other than deadline order, and exactly-once external side effects are outside scope.