executorservice

    13熱度

    1回答

    我正在使用緩存的線程池ExecutorService來運行一些異步後臺任務。我提供了將線程交給ExecutorService的ThreadFactory(無論何時需要它們)。我對高速緩存線程池的理解是,在線程閒置60秒後,它由ExecutorService定義。 我想在我的線程即將終止時執行一些狀態清理。達到此目的的最佳方法是什麼? ExecutorService不會輕易在線程的生命週期中提供鉤子

    0熱度

    2回答

    我想先安排一項任務經常發生,然後再減少一次。我寧願不爲這個添加一個依賴到Quartz。 在標準的Java庫,我已經拿出最好的是一系列的一次性任務,其次是頻率較低的線性時間表: ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); myRunnable = new MyRunnable();

    0熱度

    2回答

    所以,讓我們說,我有以下ScheduledExecutorService: public class Foo { private ScheduledExecutorService exec; public Foo() { exec = Executors.newScheduledThreadPool(NUM_OF_TASKS); }

    4熱度

    4回答

    我有一個固定的線程池,在任何時候(有一個隊列)運行7個併發線程,我想把它變成一個只運行7個併發作業的預定線程池,但可以排隊/時間表更多。 閱讀該文檔並沒有真正幫助我.. newFixedThreadPool 公共靜態的ExecutorService的newFixedThreadPool(INT來確定nthreads) 創建一個可重用操作一組固定的線程的線程池關閉 一個共享的無界隊列。如果任何線程在

    0熱度

    1回答

    我在調用線程時遇到問題。 這裏是一小段代碼片段: ExecutorService service = Executors.newFixedThreadPool(1); for(int i =0; i<30;i++){ Future<MyClass> task = service.submit(new MyThread(parameter1, parameter2)); try

    147熱度

    13回答

    的線程池 比方說,我有當我運行在調試這個應用程序,它利用Executor框架等 Executors.newSingleThreadExecutor().submit(new Runnable(){ @Override public void run(){ // do stuff } } 的應用,線程與以下(默認)創建名稱:Thread[pool-1-

    7熱度

    3回答

    我正在使用一個ExecutorService來執行一些Callables,但是這些線程的名稱就像是fixed-pool-1-thread-1。 我如何更改線程的名稱?如果這是不可能的,還有另一種方法來執行Callables,我可以設置threadS的名字?

    1熱度

    2回答

    可能重複: ExecutorService, how to wait for all tasks to finish Java ExecutorService: awaitTermination of all recursively created tasks 有沒有辦法來阻止當前線程,直到一個ExecutorService已經完成了所有任務? executor.execute(task1);

    4熱度

    6回答

    我的代碼: String[] torrentFiles = new File("/root/torrents/").list(); if(torrentFiles.length == 0 || torrentFiles == null) { System.exit(0); } ex = Executors.newFixedThre

    1熱度

    2回答

    我正在開發一個J2SE應用程序,用於同步存儲在不同服務器上的四個數據庫的184輛汽車的GPS信息。對於每一輛汽車創建一個線程和存儲在ScheduledThreadPool ScheduledExecutorService executor = Executors.newScheduledThreadPool(20); for (int i = 0; i < cars.size(); i