Code example for Exchanger

Methods: exchange

0
 
	@Override 
	public void run(){ 
		String prev = data;
		try { 
			data = exchanger.exchange(data);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} 
		System.out.println(prev + "-->" + data);
	} 
 
	/** 
	 * @param args 
	 */ 
	public static void main(String[] args) {
		ExecutorService executor = Executors.newFixedThreadPool(2);
		Exchanger<String> exchanger = new Exchanger<String>();
		executor.submit(new ExchangerShowcase("A", exchanger));
		executor.submit(new ExchangerShowcase("B", exchanger));
Stop searching for code, let great code find you!  Add Codota to your java IDE