I have variable number of threads which are used for parallel downloading. I used this,
for(int i = 0; i< sth; i++){
thrList.add(new myThread (parameters));
thrList.get(i).start();
thrList.get(i).join();
}
I don't know why but they wait for each other to complete. When using threads, I am supposed get mixed print outs, since right then there are several threads running that code. However, when I print them out, they are always in order and one thread waits for the previous one to finish first. I only want them to join the main thread, not wait for each other. I noticed that when I measured time while downloading in parallel.
How can I fix this? Why are they doing it in order?
In my .java, there is MyThread class with run and there is Downloader class with static methods and variables. Would they be the cause of this? The static methods and variables?
How can I fix this problem?
you are creating a thread, waiting for it to complete (join), creating a new thread, waiting for it to complete (join) etcetera.
you should read the java documentation regarding threads to know what most method do: http://download.oracle.com/javase/tutorial/essential/concurrency/index.html and http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With