@Slf4j
public class EventDelayQueueService {
private final List<TaskInfo> items = Collections.synchronizedList(new ArrayList<>());
private final int maxCapacity = 500;
private final ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1);;
private final MDCThreadPoolExecutor executor = Executors.newFixedThreadPool(5);;
private final AtomicInteger count = new AtomicInteger(0);
@Override
public void afterPropertiesSet() throws Exception {
log.info("start the EventDelayQueueService .");
scheduled.scheduleAtFixedRate(() -> {
if (items.size() > maxCapacity) {
asyncAction();
return;
}
if (count.incrementAndGet() > 10) {
asyncAction();
}
},10,200, TimeUnit.MILLISECONDS);
}
private void asyncAction() {
// TODO
}
public void add(TaskInfo info) {
items.add(info);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。