我正在创建一个调度程序并安排一个延迟 2 秒的作业。但在安排特定作业之前,我想检查 ScheduledExecutorService 的池大小和队列大小,但我找不到任何方法。任何人都可以向我建议如何在安排任何作业之前检查 ScheduledExecutorService 的池大小和队列大小。
//here i have created ScheduledExecutorService
private static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE;
static {
//initialized ScheduledExecutorService with 30 pool size
Scheduled_Executor_Service = (ThreadPoolExecutor) Executors.newScheduledThreadPool(30);
}
public void addTaskTOSchedule(){
//Here i want to check poolsize and queue size of SCHEDULED_EXECUTOR_SERVICE if
//ScheduledExecutorService already used more then specific number thread then i will not schedule job
SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
User user = new User();
SCHEDULED_EXECUTOR_SERVICE.execute(user);
}, 2000, TimeUnit.MILLISECONDS);
}
红糖糍粑
相关分类