How do i set up a DelayQueue's Delay

前端 未结 4 996
梦如初夏
梦如初夏 2021-01-19 04:42

I\'m just starting out coding in java i\'m in struggling with setting up a DelayQueue,

I wanted to have it so,

DelayQueue queue = new DelayQueue();

         


        
4条回答
  •  醉酒成梦
    2021-01-19 04:56

    Your "custom delay" classes must return the delay from the getDelay(TimeUnit timeUnit) method specified in the Delayed interface. E.g.

    public class MyClass implements Delayed {
        public long getDelay(TimeUnit timeUnit) {
            long delay = calculateDelaySomehow();
            return delay;
        }
    }
    

    Note that you also need to provide an implementation for compareTo().

提交回复
热议问题