I'm pretty new to multi-processing and i was wondering how much was it convenient to use them in multiple file's download. Basically, i have an application (perfectly working that downloads files (images, videos...) from an URL and i wanted to speed up this downloads (now they are sequential) splitting them on multiple threads. So i created a class "PrimeThread" overriding the run method of the thread class and runned a Thread instance in the main for every download, but i don't notice any speed up in time performances. Here's the code i wrote (in main):
for(int e = 0;e<videos.size();e++) //for every video i create a new thread
{
PrimeThread thread= new PrimeThread(downloader,path1,path2);
thread.run();
}
Here's the code I wrote in the Thread class:
import java.io.IOException;
class PrimeThread extends Thread {
HttpDownloadUtility scaricatore; //instance of the "downloader" class
String path1, path2;
PrimeThread(HttpDownloadUtility scaricatore,String path1,String path2) {
this.scaricatore = scaricatore;
this.path1 = path1;
this.path2 = path2;
}
public void run() {
try {
scaricatore.downloadMedia(path1, path2); //method of the "downloader" class that takes 2 paths in input and downloads from the 1st and put the file downloaded in the 2nd path
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}