/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.executor.support;
import java.util.AbstractQueue;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/**
* A clone of {@linkplain java.util.concurrent.LinkedBlockingQueue}
* with the addition of a {@link #setCapacity(int)} method, allowing us to
* change the capacity of the queue while it is in use.<p>
* <p>
* The documentation for LinkedBlockingQueue follows...<p>
* <p>
* An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
* linked nodes.
* This queue orders elements FIFO (first-in-first-out).
* The <em>head</em> of the queue is that element that has been on the
* queue the longest time.
* The <em>tail</em> of the queue is that element that has been on the
* queue the shortest time. New elements
* are inserted at the tail of the queue, and the queue retrieval
* operations obtain elements at the head of the queue.
* Linked queues typically have higher throughput than array-based queues but
* less predictable performance in most concurrent applications.
*
* <p> The optional capacity bound constructor argument serves as a
* way to prevent excessive queue expansion. The capacity, if unspecified,
* is equal to {@link Integer#MAX_VALUE}. Linked nodes are
* dynamically created upon each insertion unless this would bring the
* queue above capacity.
*
* <p>This class implements all of the <em>optional</em> methods
* of the {@link Collection} and {@link Iterator} interfaces.
*
* <p>This class is a member of the
* <a href="{@docRoot}/../guide/collections/index.html">
* Java Collections Framework</a>.
*
* @param <E> the type of elements held in this collection
* @author Doug Lea
* @since 1.5
**/
public class ResizableCapacityLinkedBlockingQueue<E> extends AbstractQueue<E>
implements
BlockingQueue<E>,
java.io.Serializable {
private static final long serialVersionUID = -6903933977591709194L;
/*
* A variant of the "two lock queue" algorithm. The putLock gates entry to put (and offer), and has an associated condition for waiting puts. Similarly for the takeLock. The "count" field that
* they both rely on is maintained as an atomic to avoid needing to get both locks in most cases. Also, to minimize need for puts to get takeLock and vice-versa, cascading notifies are used. When
* a put notices that it has enabled at least one take, it signals taker. That taker in turn signals others if more items have been entered since the signal. And symmetrically for takes signalling
* puts. Operations such as remove(Object) and iterators acquire both locks.
*/
/**
* Linked list node class
*/
static class Node<E> {
/**
* The item, volatile to ensure barrier separating write and read
*/
volatile E item;
Node<E> next;
Node(E x) {
item = x;
}
}
/**
* The capacity bound, or Integer.MAX_VALUE if none
*/
private int capacity;
/**
* Current number of elements
*/
private final AtomicInteger count = new AtomicInteger(0);
/**
* Head of linked list
*/
private transient Node<E> head;
/**
* Tail of linked list
*/
private transient Node<E> last;
/**
* Lock held by take, poll, etc
*/
private final ReentrantLock takeLock = new ReentrantLock();
/**
* Wait queue for waiting takes
*/
private final Condition notEmpty = takeLock.newCondition();
/**
* Lock held by put, offer, etc
*/
private final ReentrantLock putLock = new ReentrantLock();
/**
* Wait queue for waiting puts
*/
private final Condition notFull = putLock.newCondition();
/**
* Signal a waiting take. Called only from put/offer (which do not
* otherwise ordinarily lock takeLock.)
*/
private void signalNotEmpty() {
final ReentrantLock takeLock = this.takeLock;
takeLock.lock();
try {
notEmpty.signal();
} finally {
takeLock.unlock();
}
}
/**
* Signal a waiting put. Called only from take/poll.
*/
private void signalNotFull() {
final ReentrantLock putLock = this.putLock;
putLock.lock();
try {
notFull.signal();
} finally {
putLock.unlock();
}
}
/**
* Create a node and link it at end of queue
*
* @param x the item
*/
private void insert(E x) {
last = last.next = new Node<E>(x);
}
/**
* Remove a node from head of queue,
*
* @return the node
*/
private E extract() {
Node<E> first = head.next;
head = first;
E x = first.item;
first.item = null;
return x;
}
/**
* Lock to prevent both puts and takes.
*/
private void fullyLock() {
putLock.lock();
takeLock.lock();
}
/**
* Unlock to allow both puts and takes.
*/
private void fullyUnlock() {
takeLock.unlock();
putLock.unlock();
}
/**
* Creates a <tt>LinkedBlockingQueue</tt> with a capacity of
* {@link Integer#MAX_VALUE}.
*/
public ResizableCapacityLinkedBlockingQueue() {
this(Integer.MAX_VALUE);
}
/**
* Creates a <tt>LinkedBlockingQueue</tt> with the given (fixed) capacity.
*
* @param capacity the capacity of this queue.
* @throws IllegalArgumentException if <tt>capacity</tt> is not greater
* than zero.
*/
public ResizableCapacityLinkedBlockingQueue(int capacity) {
if (capacity <= 0) {
throw new IllegalArgumentException();
}
this.capacity = capacity;
last = head = new Node<E>(null);
}
/**
* Creates a <tt>LinkedBlockingQueue</tt> with a capacity of
* {@link Integer#MAX_VALUE}, initially containing the elements of the
* given collection,
* added in traversal order of the collection's iterator.
*
* @param c the collection of elements to initially contain
* @throws NullPointerException if <tt>c</tt> or any element within it
* is <tt>null</tt>
*/
public ResizableCapacityLinkedBlockingQueue(Collection<? extends E> c) {
this(Integer.MAX_VALUE);
for (Iterator<? extends E> it = c.iterator(); it.hasNext();) {
add(it.next());
}
}
// this doc comment is overridden to remove the reference to collections
// greater in size than Integer.MAX_VALUE
/**
* Returns the number of elements in this queue.
*
* @return the number of elements in this queue.
*/
@Override
public int size() {
return count.get();
}
/**
* Set a new capacity for the queue. Increasing the capacity can
* cau
没有合适的资源?快使用搜索试试~ 我知道了~
强大的动态线程池框架,附带监控报警功能
共1450个文件
java:721个
md:201个
js:107个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 144 浏览量
2023-04-27
09:33:49
上传
评论
收藏 7.95MB ZIP 举报
温馨提示
强大的动态线程池框架,附带监控报警功能。支持 JDK、Tomcat、Jetty、Undertow 线程池;Dubbo、Dubbox、Kafka、RabbitMQ、RocketMQ、Hystrix 消费线程池(更多框架线程池还在适配中)。内置两种使用模式:轻量级依赖配置中心以及无中间件依赖版本。
资源推荐
资源详情
资源评论
收起资源包目录
强大的动态线程池框架,附带监控报警功能 (1450个子文件)
cn.hippo4j.common.api.ClientNetworkService 60B
cn.hippo4j.common.api.ClientNetworkService 60B
startup.cmd 1KB
shutdown.cmd 343B
lombok.config 905B
index.css 414KB
app.6f535c21.css 251KB
custom.css 8KB
chunk-5911c282.13a7e89e.css 5KB
chunk-libs.3dfb7769.css 3KB
chunk-1f79669e.db982a1e.css 3KB
chunk-1c21bf70.2e4c2f94.css 2KB
chunk-eee8a83e.a09ed6a0.css 1KB
waves.css 825B
chunk-6a55e40a.95ae0d9d.css 763B
chunk-296c90bf.95ae0d9d.css 763B
chunk-d9fc0e72.95ae0d9d.css 763B
chunk-37b6768d.54599d3b.css 763B
chunk-05d50b2c.95ae0d9d.css 763B
chunk-19132c4b.95ae0d9d.css 763B
chunk-2e217faa.95ae0d9d.css 763B
chunk-0eddb806.9ba52545.css 749B
chunk-ef888edc.5f8941eb.css 745B
chunk-d6c1d344.35874984.css 631B
chunk-a89383d2.35874984.css 631B
chunk-078a7535.35874984.css 631B
chunk-5428753b.35874984.css 631B
chunk-4f40863a.35874984.css 631B
chunk-60c39f89.35874984.css 631B
chunk-adca2a60.35874984.css 631B
chunk-149a43cf.35874984.css 631B
chunk-1b3cdbc8.35874984.css 631B
chunk-3a6f2dc9.35874984.css 631B
index.module.css 365B
styles.module.css 138B
cn.hippo4j.common.executor.support.CustomBlockingQueue 42B
cn.hippo4j.common.executor.support.CustomRejectedExecutionHandler 64B
.env.development 565B
Dockerfile 2KB
.editorconfig 244B
.eslintignore 40B
spring.factories 243B
spring.factories 229B
spring.factories 179B
spring.factories 179B
spring.factories 153B
spring.factories 152B
spring.factories 147B
spring.factories 144B
spring.factories 143B
spring.factories 143B
spring.factories 142B
spring.factories 140B
spring.factories 138B
spring.factories 137B
spring.factories 137B
spring.factories 125B
spring.factories 114B
401.089007e7.gif 160KB
401.gif 160KB
hippo4j.gif 6KB
hippo4j.ecba1844.gif 6KB
hippo4j.gif 6KB
.gitignore 531B
.gitignore 256B
index.html 5KB
index.html 488B
favicon.ico 4KB
favicon.ico 3KB
hippo4j_favicon.ico 3KB
favicon.ico 3KB
cn.hippo4j.rpc.discovery.InstanceServerLoader 835B
cn.hippo4j.common.extension.spi.IOldSpi 44B
maven-wrapper.jar 0B
ResizableCapacityLinkedBlockingQueue.java 25KB
DefaultThreadPoolPluginManager.java 17KB
DynamicThreadPoolRefreshListener.java 17KB
ConfigServiceImpl.java 15KB
DynamicThreadPoolPostProcessor.java 15KB
ThreadPoolBuilder.java 14KB
ExtensibleThreadPoolExecutor.java 13KB
ClientWorker.java 13KB
LongPollingService.java 12KB
HttpUtil.java 12KB
DynamicThreadPoolAutoConfiguration.java 12KB
DynamicThreadPoolExecutor.java 11KB
ReflectUtil.java 11KB
DynamicThreadPoolPostProcessor.java 11KB
ThreadPoolController.java 11KB
BlockingQueueTypeEnum.java 11KB
DefaultThreadPoolCheckAlarmHandler.java 10KB
KafkaThreadPoolAdapter.java 10KB
StringUtil.java 10KB
DefaultGlobalThreadPoolPluginManagerTest.java 10KB
IoUtil.java 10KB
DashboardServiceImpl.java 10KB
DefaultThreadPoolPluginManagerTest.java 9KB
TomcatWebThreadPoolHandlerSupport.java 9KB
SpringCloudStreamRabbitMQThreadPoolAdapter.java 9KB
TaskTimeRecordPlugin.java 9KB
共 1450 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功