Example #1
0
 /**
  * Transfer the contents of src to dest in a synchronized manner (since SimpleQueue doesn't have
  * internal synchronization).
  */
 public static void transfer(SimpleQueue<String> src, SimpleQueue<String> dest)
     throws InterruptedException {
   // Acquire the locks for src and dest.
   synchronized (src) {
     synchronized (dest) {
       // Remove each element from src and put it into dest.
       while (!src.isEmpty()) {
         dest.put(src.take());
       }
     }
   }
 }