美文网首页
【BlockingQueue】SynchronousQueue

【BlockingQueue】SynchronousQueue

作者: 有章 | 来源:发表于2018-08-16 11:33 被阅读0次

JDK自带的线程池可以创建缓存的线程池:来一个任务就创建一个线程

ExecutorService executorService= Executors.newCachedThreadPool();
corePoolSize:0
maxPoolSize=INTERNAL.MAX_VALUE
阻塞队列:SynchronousQueue,实现了BlockingQueue接口

SynchronousQueue:
当一个线程put操作时会阻塞,等待一个消费线程执行take操作,同时消费线程会唤醒put的生产线程
内部实现了公平队列和非公平队列

公平:先进先出
        TransferQueue() {
            QNode h = new QNode(null, false); // initialize to dummy node.
            head = h;
            tail = h;
        }
非公平:先进后厨
new TransferStack()

【参考博客】
https://blog.csdn.net/yanyan19880509/article/details/52562039

相关文章

网友评论

      本文标题:【BlockingQueue】SynchronousQueue

      本文链接:https://www.haomeiwen.com/subject/izmnbftx.html