簡體   English   中英

運行多個線程

[英]Running Multiple Threads

我正在使用1個線程執行2個任務

  1. 讀取文件
  2. 下載文件

     scheduledExecutorService1 = Executors.newScheduledThreadPool(1); 

但是對於多個文件,每個線程都會有一個延遲。

使用以下代碼會導致重復

scheduledExecutorService1 = Executors.newScheduledThreadPool(2);

與多個線程一起處理延遲並避免重復的代碼將是正確的代碼。

最好創建兩個ExecutorService,一個用於讀取文件,另一個用於下載文件。

       ExecutorService readService = Executors.newScheduledThreadPool(1);

       ExecutorService downloadService = Executors.newScheduledThreadPool(1);

暫無
暫無

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

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