DelayedQueue

Interfaces to be implemented

public interface Scheduler
{
    void schedule( Task t, long delayMs );
}

public interface Task
{
    void run();
}

Single thread

  • Main thread is in Timedwaiting state for delayMs for each call of schedule()

  • Only one thread, very low CPU utilization

  • Also, this is not working as later call

  • How about sleeping in other threads

One thread for each task

  • No blocking when calling schedule

  • What happens if we call schedule many times

    • A lot of thread creation overhead

  • Call be alleviated by using a thread pool, but still not ideal

PriorityQueue + A background thread

Last updated

Was this helpful?