RocketMq学习-用到了哪些JUC的工具

241 阅读1分钟

并发锁

ReentrantReadWriteLock:ProcessQueue.treeMapLock

ReentrantLock: ProcessQueue.consumeLock

AtomicLong: ProcessQueue.msgCount、msgSize

Semphore: SemaphoreReleaseOnlyOnce


在SemaphoreReleaseOnlyOnce中使用AtomicBoolean实现一个SemaphoreReleaseOnlyOnce只被释放一次


// 信号量,限制正在进行的异步请求的最大数量(65535),从而保护系统内存占用。
NettyRemotingAbstract.semaphoreAsync

NettyRemotingAbstract#invokeAsyncImpl 
-> boolean acquired = this.semaphoreAsync.tryAcquire(timeoutMillis, TimeUnit.MILLISECONDS);
-> acquired为true才会调用发送请求

CountDownLatch:CountDownLacth2、responseTable

并发工具

ConcurrentHashMap

CompletableFuture

LinkedBlockingQueue

PriorityBlockingQueue

ArrayBlockingQueue