Instead of using threads directly, it’s better to use an ExecutorService and run all download tasks through this service. Sort of:
ExecutorService service = Executors.newCachedThreadPool(); Downloader down = new Downloader("http:xxxxx", new File("./references/word.txt"), new File("./references/words.txt")); Downloader down2 = new Downloader("http:xxxx", new File("./references/word1.txt"), new File("./references/words1.txt")); service.invokeAll(Arrays.asList(down, down2));
In your Downloader class, the Callable interface should be implemented.
source share