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
Post a Comment