Redisson PermitExpirableSemaphore 剖析

某些场景下需要考虑信号量机制,比如控制整体的并发量,redisson提供了在分布式环境下的解决方案,即 PermitExpirableSemaphore。
记录一下,主要是是否会重复初始化导致重置可用信号量、如何变更总可用信号量。
使用非常简单,以下是官方的使用示例:
RPermitExpirableSemaphore semaphore = redisson.getPermitExpirableSemaphore("mySemaphore");

semaphore.trySetPermits(23);

// acquire permit
String id = semaphore.acquire();

// or acquire permit with lease time in 10 seconds
String id = semaphore.acquire(10, TimeUnit.SECONDS);

// or try to acquire permit
String id = semaphore.tryAcquire()

Redisson PermitExpirableSemaphore 剖析最先出现在Python成神之路

版权声明:
作者:玉兰
链接:https://www.techfm.club/p/27952.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>