摘要: exchanger用于两个线程交换数据 /** * 两个线程交换数据,A线程发送数据给B线程,B线程接受的数据和A发送的数据是同一个对象 * A will send the Object java.lang.Object@6e22e576 * B will send the Object java. 阅读全文
posted @ 2019-11-17 23:17 踏月而来 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 一个生产者和一个消费者 public class ConditionTest { private static ReentrantLock lock = new ReentrantLock(); private static Condition condition = lock.newConditi 阅读全文
posted @ 2019-11-17 23:14 踏月而来 阅读(367) 评论(0) 推荐(0) 编辑
摘要: /** * 这里只是将Semaphore包装了一下,注意当Semaphore的构造参数是1时,本身就是一个显示锁 */ public class SemaphoreLock { private final Semaphore semaphore = new Semaphore(1); public 阅读全文
posted @ 2019-11-17 15:53 踏月而来 阅读(296) 评论(0) 推荐(0) 编辑