multithreading issue

hello, I need a suggestion for multithreading issue.

I download remote data from two URL sources. In main thread I create 2 new threads which asynch. downloading is performed. When I created this threads in main thread I wait until all threads for data downloading is done.

public void doSomething() {

DownloadThread t1 = new DownloadThread(url);

t1.start();

DownloadThread t2 = new DownloadThread(url);

t2.start();

// here I want wait until both threads will done

// ?

}

class DownloadThread extends Thread {

public void run() {

// downloading

}

public boolean isComplete() {

return true; // if downloaded is done

}

}

[738 byte] By [radim.slovaceka] at [2007-11-27 0:40:11]
# 1
try to join the thread you want to wait.for reference : http://java.sun.com/docs/books/tutorial/essential/concurrency/join.html
NourElsaftya at 2007-7-11 22:52:52 > top of Java-index,Java Essentials,Java Programming...
# 2

public void doSomething() {

DownloadThread t1 = new DownloadThread(url);

t1.start();

DownloadThread t2 = new DownloadThread(url);

t2.start();

// here I want wait until both threads will done

The thread caller (I suppose main) waits until t1 and t2 will come off.

t1.join();

t2.join();

}

puntinoa at 2007-7-11 22:52:52 > top of Java-index,Java Essentials,Java Programming...