### Question:
PriorityDelayQueue extends AbstractQueue<PriorityDelayQueue.QueueElement<E>> implements BlockingQueue<PriorityDelayQueue.QueueElement<E>> { protected void antiStarvation() { long now = System.currentTimeMillis(); if (now - lastAntiStarvationCheck > ANTI_STARVATION_INTERVAL) { for (int i = 0; i < queues.length - 1; i++) { antiStarvation(queues[i], queues[i + 1], "from P[" + i + "] to P[" + (i + 1) + "]"); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < queues.length; i++) { sb.append("P[").append(i).append("]=").append(queues[i].size()).append(" "); } debug("sub-queue sizes: {0}", sb.toString()); lastAntiStarvationCheck = System.currentTimeMillis(); } } @SuppressWarnings("unchecked")  PriorityDelayQueue(int priorities, long maxWait, TimeUnit unit, int maxSize); int getPriorities(); long getMaxWait(TimeUnit unit); long getMaxSize(); @Override @SuppressWarnings("unchecked") Iterator<QueueElement<E>> iterator(); @Override int size(); int[] sizes(); @Override boolean add(QueueElement<E> queueElement); @Override boolean offer(QueueElement<E> queueElement); @Override QueueElement<E> poll(); @Override QueueElement<E> peek(); @Override void put(QueueElement<E> e); @Override boolean offer(QueueElement<E> e, long timeout, TimeUnit unit); @Override QueueElement<E> take(); @Override QueueElement<E> poll(long timeout, TimeUnit unit); @Override int remainingCapacity(); @Override int drainTo(Collection<? super QueueElement<E>> c); @Override int drainTo(Collection<? super QueueElement<E>> c, int maxElements); @Override void clear(); static final long ANTI_STARVATION_INTERVAL; }### Answer:
@Test public void testAntiStarvation() throws Exception { PriorityDelayQueue<Integer> q = new PriorityDelayQueue<Integer>(3, 500, TimeUnit.MILLISECONDS, -1); q.offer(new TestQueueElement<Integer>(1)); q.peek(); assertEquals(1, q.sizes()[0]); Thread.sleep(600); q.peek(); assertEquals(1, q.sizes()[1]); Thread.sleep(600); q.peek(); assertEquals(1, q.sizes()[2]); }