第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 ScheduledExecutorService 獲取隊(duì)列和池大小

如何從 ScheduledExecutorService 獲取隊(duì)列和池大小

拉風(fēng)的咖菲貓 2023-09-06 16:45:10
我正在創(chuàng)建一個調(diào)度程序并安排一個延遲 2 秒的作業(yè)。但在安排特定作業(yè)之前,我想檢查 ScheduledExecutorService 的池大小和隊(duì)列大小,但我找不到任何方法。任何人都可以向我建議如何在安排任何作業(yè)之前檢查 ScheduledExecutorService 的池大小和隊(duì)列大小。   //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 jobSCHEDULED_EXECUTOR_SERVICE.schedule(() -> {                    User user = new User();                    SCHEDULED_EXECUTOR_SERVICE.execute(user);                }, 2000, TimeUnit.MILLISECONDS);}
查看完整描述

1 回答

?
紅糖糍粑

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個贊

ScheduledExecutorService 接口不允許訪問內(nèi)部隊(duì)列。您必須將服務(wù)轉(zhuǎn)換為實(shí)現(xiàn)類才能獲取隊(duì)列的大小,如下所示:


ScheduledExecutorService Scheduled_Executor_Service = Executors.newScheduledThreadPool(30);

        if (Scheduled_Executor_Service instanceof ScheduledThreadPoolExecutor) {

            ScheduledThreadPoolExecutor implementation = (ScheduledThreadPoolExecutor) Scheduled_Executor_Service;

            int size = implementation.getQueue().size();


        }


查看完整回答
反對 回復(fù) 2023-09-06
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號