ExchangerDemo
Posted nihaofenghao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ExchangerDemo相关的知识,希望对你有一定的参考价值。
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){ } } }); } }
以上是关于ExchangerDemo的主要内容,如果未能解决你的问题,请参考以下文章