Code example for Exchanger

0
package example; 
 
import java.util.ArrayList; 
import java.util.List; 
import java.util.concurrent.Exchanger; 
 
public class ExchangerTest { 
 
	Exchanger exchanger = new Exchanger();
	List exchnagerList = new ArrayList();
 
	class AddList implements Runnable {
		public void run() { 
			try { 
				while (true) { 
					exchnagerList.add("1");
					if (exchnagerList.size() == 1) {
						exchnagerList = (List) exchanger.exchange(exchnagerList);
					} 
				} 
			} catch (InterruptedException ex) {
				System.out.println(ex);
			} 
		}