for (int i = deliveries.size() - 1; i >= 0; i--)
List toCancel = new ArrayList();  Iterator iter = deliveries.values().iterator(); while (iter.hasNext()) { SingleReceiverDelivery d = (SingleReceiverDelivery)iter.next(); toCancel.add(d); }  for (int i = toCancel.size() - 1; i >= 0; i--)
   synchronized void cancelAllDeliveries() throws JMSException   {      if (log.isTraceEnabled()) { log.trace(this + " cancels deliveries"); }            //Need to cancel starting at the end of the list and working to the front      //in order that the messages end up back in the correct order in the channel            for (int i = deliveries.size() - 1; i >= 0; i--)      {            SingleReceiverDelivery d = (SingleReceiverDelivery)deliveries.get(i);         try         {            boolean cancelled = d.cancel();            if (!cancelled)            {               throw new JMSException("Failed to cancel delivery:" + d.getReference().getMessageID());            }                        if (log.isTraceEnabled()) { log.trace(d +  " canceled"); }         }         catch(Throwable t)         {            log.error("Cannot cancel delivery: " + d, t);         }                  }      deliveries.clear();      promptDelivery();   }