基于Spring Boot的线程池监控方案 |
您所在的位置:网站首页 › io密集型线程池设置 › 基于Spring Boot的线程池监控方案 |
/** * 可重新设定队列大小的阻塞队列 * * @author wangtongzhou * @since 2022-03-13 11:54 */public class ResizableCapacityLinkedBlockingQueue extends AbstractQueue implements BlockingDeque, java.io.Serializable { /* * Implemented as a simple doubly-linked list protected by a * single lock and using conditions to manage blocking. * * To implement weakly consistent iterators, it appears we need to * keep all Nodes GC-reachable from a predecessor dequeued Node. * That would cause two problems: * - allow a rogue Iterator to cause unbounded memory retention * - cause cross-generational linking of old Nodes to new Nodes if * a Node was tenured while live, which generational GCs have a * hard time dealing with, causing repeated major collections. * However, only non-deleted Nodes need to be reachable from * dequeued Nodes, and reachability does not necessarily have to * be of the kind understood by the GC. We use the trick of * linking a Node that has just been dequeued to itself. Such a * self-link implicitly means to jump to "first" (for next links) * or "last" (for prev links). */ /* * We have "diamond" multiple interface/abstract class inheritance * here, and that introduces ambiguities. Often we want the * BlockingDeque javadoc combined with the AbstractQueue * implementation, so a lot of method specs are duplicated here. */ private static final long serialVersionUID = -387911632671998426L; /** * Doubly-linked list node class */ static final class Node { /** * The item, or null if this node has been removed. */ E item; /** * One of: * - the real predecessor Node * - this Node, meaning the predecessor is tail * - null, meaning there is no predecessor */ Node prev; /** * One of: * - the real successor Node * - this Node, meaning the successor is head * - null, meaning there is no successor */ Node next; Node(E x) { item = x; } } /** * Pointer to first node. * Invariant: (first == null && last == null) || * (first.prev == null && first.item != null) */ transient Node first; /** * Pointer to last node. * Invariant: (first == null && last == null) || * (last.next == null && last.item != null) */ transient Node last; /** * Number of items in the deque */ private transient int count; /** * Maximum number of items in the deque */ private volatile int capacity; public int getCapacity() { return capacity; } public void setCapacity(int capacity) { this.capacity = capacity; } /** * Main lock guarding all access */ final ReentrantLock lock = new ReentrantLock(); /** * Condition for waiting takes */ private final Condition notEmpty = lock.newCondition(); /** * Condition for waiting puts */ private final Condition notFull = lock.newCondition(); /** * Creates a {@code ResizableCapacityLinkedBlockIngQueue} with a capacity of * {@link Integer#MAX_VALUE}. */ public ResizableCapacityLinkedBlockingQueue() { this(Integer.MAX_VALUE); } /** * Creates a {@code ResizableCapacityLinkedBlockIngQueue} with the given (fixed) capacity. * * @param capacity the capacity of this deque * @throws IllegalArgumentException if {@code capacity} is less than 1 */ public ResizableCapacityLinkedBlockingQueue(int capacity) { if (capacity |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |