/** * 当向SynchronousQueue插入元素时,必须同时有个线程往外取 * SynchronousQueue是没有容量的,这是与其他的阻塞队列不同的地方 */ public class SynchronusQueueTest { static SynchronousQueuequeue = new SynchronousQueue<>(); public static void main(String[] args) throws InterruptedException { Executors.newCachedThreadPool().submit(()->{ try { queue.take(); } catch (InterruptedException e) { e.printStackTrace(); } }); queue.put("hello"); System.out.println("=========="); } }