Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default about array Thread

    exp, i create array nameThread tpye class DownloadThread

    DownloadThread[] nameThread = new DownloadThread[100];
    for(int i=0;i<100;i++)
    nameThread[i] = new DownloadThread(strUrl);

    now,I don't know ..how to know all Threads run finished.
    plz help me.

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    You can use the CountDownLatch class. The idea is that you create a CountDownLatch with the number of threads you'll have, then waiting on this latch (note "await", not "wait"!):

    Java Code:
    CountDownLatch latch = new CountDownLatch(100);
    // ... create threads, passing them 'latch', and start them
    latch.await();
    Then, each thread ends by counting down the latch:

    Java Code:
    // thread's run method
    public void run() {
      try {
        // ... do exciting thing
      } finally {
        latch.countDown();
      }
    }

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 05:37 PM
  2. passing a value from parent thread to child thread
    By sachinj13 in forum Threads and Synchronization
    Replies: 7
    Last Post: 09-07-2008, 09:06 PM
  3. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 10:30 PM
  4. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •