简体   繁体   中英

Running Multiple Threads

I am using 1 thread for 2 tasks

  1. Reading file
  2. Download file

     scheduledExecutorService1 = Executors.newScheduledThreadPool(1); 

But with multiple files, there will be a delay per thread.

Using the following code causes duplicates :

scheduledExecutorService1 = Executors.newScheduledThreadPool(2);

What will be the correct code to run with multiple threads handling delays and avoiding dulication.

It is better to create two ExecutorService one for reading file another for downloading file.

       ExecutorService readService = Executors.newScheduledThreadPool(1);

       ExecutorService downloadService = Executors.newScheduledThreadPool(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM