标签:cat imp static err str mes interview bsp pre
package com.fh.interview; import java.util.concurrent.Exchanger; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * @author * @create 2018-06-03 下午4:31 **/ public class ExchangerDemo { private static Exchanger<String> exchanger = new Exchanger(); public static void main(String[] args) { ExecutorService pool = Executors.newFixedThreadPool(2); pool.execute(new Runnable() { @Override public void run() { try { String mess = exchanger.exchange("hi"); System.out.println("1:"+mess); }catch (Exception e){ } } }); pool.execute(new Runnable() { @Override public void run() { try { String aaa = exchanger.exchange("hello"); System.out.println("2"+aaa); }catch (Exception e){ } } }); } }
标签:cat imp static err str mes interview bsp pre
原文地址:https://www.cnblogs.com/nihaofenghao/p/9129589.html