multithreading - Java downloader - downloading multiple files -


i have created java program can download 1 file using url, wish download multiple files using multiple threads. use same method , loop on list of urls files? or recommend way go it?

you use this:

void download(url url){     ... }  void downloadall(url[] urls){     for(url url : urls){         thread t = new thread(() -> download(url));         t.start();     } } 

edit:
@louisf. mentioned recommended way solve problem executors though. instead of simple example using threads , more proper, aswell bit more complex approach:

executorservice service = executors.newchachedthreadpool(); for(url url : urls)     service.submit(() -> download(url); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -