/*
* 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
没有合适的资源?快使用搜索试试~ 我知道了~
hippo4j-develop.zip
共1338个文件
java:675个
md:158个
js:107个
0 下载量 3 浏览量
2023-03-14
17:29:40
上传
评论
收藏 6.62MB ZIP 举报
温馨提示
强大的动态线程池框架,附带监控报警功能。支持 JDK、Tomcat、Jetty、Undertow 线程池;Dubbo、Dubbox、RabbitMQ、RocketMQ、Hystrix 消费线程池(更多框架线程池还在适配中)。内置两种使用模式:轻量级依赖配置中心以及无中间件依赖版本。
资源推荐
资源详情
资源评论
收起资源包目录
hippo4j-develop.zip (1338个子文件)
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.7688af8b.css 251KB
custom.css 8KB
chunk-5911c282.13a7e89e.css 5KB
chunk-libs.3dfb7769.css 3KB
chunk-8a8e7eda.3b4159c4.css 3KB
chunk-1c21bf70.2e4c2f94.css 2KB
chunk-54487101.c318f073.css 1KB
waves.css 825B
chunk-37b6768d.54599d3b.css 763B
chunk-6a55e40a.95ae0d9d.css 763B
chunk-d9fc0e72.95ae0d9d.css 763B
chunk-19132c4b.95ae0d9d.css 763B
chunk-05d50b2c.95ae0d9d.css 763B
chunk-1c44a627.95ae0d9d.css 763B
chunk-2e217faa.95ae0d9d.css 763B
chunk-65cbbb82.fcbf3365.css 749B
chunk-ef888edc.5f8941eb.css 745B
chunk-d6c1d344.35874984.css 631B
chunk-078a7535.35874984.css 631B
chunk-4f40863a.35874984.css 631B
chunk-a89383d2.35874984.css 631B
chunk-5428753b.35874984.css 631B
chunk-3a6f2dc9.35874984.css 631B
chunk-149a43cf.35874984.css 631B
chunk-adca2a60.35874984.css 631B
chunk-60c39f89.35874984.css 631B
chunk-1b3cdbc8.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 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 140B
spring.factories 138B
spring.factories 137B
spring.factories 137B
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
maven-wrapper.jar 0B
ResizableCapacityLinkedBlockingQueue.java 25KB
DefaultThreadPoolPluginManager.java 17KB
DynamicThreadPoolRefreshListener.java 16KB
DynamicThreadPoolPostProcessor.java 15KB
ConfigServiceImpl.java 15KB
ThreadPoolBuilder.java 14KB
ExtensibleThreadPoolExecutor.java 13KB
LongPollingService.java 12KB
HttpUtil.java 12KB
ClientWorker.java 12KB
DynamicThreadPoolAutoConfiguration.java 12KB
DynamicThreadPoolExecutor.java 11KB
ReflectUtil.java 11KB
BlockingQueueTypeEnum.java 11KB
DynamicThreadPoolPostProcessor.java 11KB
ThreadPoolController.java 11KB
DefaultThreadPoolCheckAlarmHandler.java 10KB
KafkaThreadPoolAdapter.java 10KB
StringUtil.java 10KB
DefaultGlobalThreadPoolPluginManagerTest.java 10KB
IoUtil.java 10KB
TomcatWebThreadPoolHandler.java 10KB
DashboardServiceImpl.java 10KB
DefaultThreadPoolPluginManagerTest.java 9KB
SpringCloudStreamRabbitMQThreadPoolAdapter.java 9KB
TaskTimeRecordPlugin.java 9KB
ThreadPoolPluginSupportTest.java 9KB
ExtensibleThreadPoolExecutorTest.java 9KB
共 1338 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mybatis中的动态sql, 涉及 where trim set if foreach等
- 简单- 快递运输(Java & JS & Python & C).html
- mybatis框架 更改ems系统,使用动态sql等.zip
- 易语言工具条下拉菜单实现
- Mybatis动态SQL高级映射.zip
- 源码esp8266开发板机智云机智云智能灯
- Python实现多图像转换成连贯的PDF文件,支持所有图片格式,可预览、裁剪、自定义PDF布局、设置图像顺序、PDF质量选择等
- H5腾讯地图选择位置组件
- 基于UCC28019+LM5017电源板硬件(原理图+PCB)工程文件.zip
- 源码esp8266开发板机智云机智云空气净化器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功