mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-01 20:13:12 +08:00
🎨 #2663 优化重复消息检查器多实例导致多守护线程的问题,修改成单例+定时任务线程池处理
This commit is contained in:
committed by
GitHub
parent
41bb3b9901
commit
95be03bf1c
@ -0,0 +1,45 @@
|
||||
package me.chanjar.weixin.common.api;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author jiangby
|
||||
* @version 1.0
|
||||
* @description: 作用
|
||||
* @date 2022/5/26 1:46
|
||||
*/
|
||||
@Test
|
||||
public class WxMessageInMemoryDuplicateCheckerSingletonTest {
|
||||
|
||||
private static WxMessageInMemoryDuplicateCheckerSingleton checkerSingleton = WxMessageInMemoryDuplicateCheckerSingleton.getInstance();
|
||||
|
||||
public void test() throws InterruptedException {
|
||||
Long[] msgIds = new Long[]{1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L};
|
||||
|
||||
// 第一次检查
|
||||
for (Long msgId : msgIds) {
|
||||
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
// 初始化后1S进行检查 每五秒检查一次,过期时间为15秒,过15秒再检查
|
||||
TimeUnit.SECONDS.sleep(15);
|
||||
for (Long msgId : msgIds) {
|
||||
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
// 过6秒再检查
|
||||
TimeUnit.SECONDS.sleep(6);
|
||||
for (Long msgId : msgIds) {
|
||||
boolean result = checkerSingleton.isDuplicate(String.valueOf(msgId));
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user