簡體   English   中英

使用executor.shutdown()

[英]The use of executor.shutdown()

看下面這段代碼:

     public void pinger()
     {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
        executor.scheduleAtFixedRate(runnable, start, rate, TimeUnit.SECONDS);
        executor.shutdown();
     }

在這種情況下是否有任何寫入shutdown命令的用法? 不同的客戶端將創建自己的可運行對象並調用此函數。

關閉執行程序時,不會接受任何新任務。 由於您在pinger方法中創建了一個新任務,因此每個任務都有自己的執行程序。 寫入時關閉只會在更正corrent任務后釋放資源。

一些說明:

  1. 您不應為每個客戶端請求創建Executor
  2. 在客戶端請求之外創建Executor並將任務提交給Executor
  3. 當您決定不接受Executor新任務時,請關閉執行程序。 關閉Executor的正確方法在下面的帖子中解釋:

如何強制關閉java ExecutorService

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM