yinjihuan / kitty

Spring Cloud & Spring Cloud Alibaba 基础框架,内置了 Cat 监控,互联网公司落地 Spring Cloud 架构必备。
650 stars 284 forks source link

ResizableCapacityLinkedBlockIngQueue 关于更改队列长度的问题 #17

Open mushang8923 opened 3 years ago

mushang8923 commented 3 years ago

1.从代码上看只是开放了setCapacity的入口,且capacity是通过volatile修饰的,所以capacity的变化会及时通知到各个线程, 关键问题是,当我往队列里插入或者取对象的时候,会有个判断 public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); // Note: convention in all put/take/etc is to preset local var // holding count negative to indicate failure unless set. int c = -1; ResizableCapacityLinkedBlockIngQueue.Node node = new ResizableCapacityLinkedBlockIngQueue.Node(e); final ReentrantLock putLock = this.putLock; final AtomicInteger count = this.count; putLock.lockInterruptibly(); try { /*

如果这个时候我调整了假设当前的任务数量是100,capacity是200,现在我调整capacity的大小为50,这个时候根据这个判断count.get() == capacity,任务队列是没有满的,这样还会往队列里塞数据,不知道我理解的对不对,是不是调整为count.get()>=capacity

zcerhub commented 3 years ago

是的,在一个博客中的做法是参考rabbitmq-java-client项目中的 VariableLinkedBlockingQueue.java这类实现的。博客的地址是:https://blog.imr3.com/tech/dynamically-adjust-threadpool-configuration/