Thread-end monitoring

Discussion in 'Java' started by mark, Nov 12, 2006.

  1. mark

    mark Guest

    Hello,

    I have constructed several threads in my application (it is such that
    some threads start other threads, etc.). Now I would like to have a
    possibility to execute some actions just when all the threads finished
    (i.e. go out from the run function). Is there any nice way to do it?

    Regards, mark
     
    mark, Nov 12, 2006
    #1
    1. Advertising

  2. mark

    Deniz Dogan Guest

    mark wrote:
    > Hello,
    >
    > I have constructed several threads in my application (it is such that
    > some threads start other threads, etc.). Now I would like to have a
    > possibility to execute some actions just when all the threads finished
    > (i.e. go out from the run function). Is there any nice way to do it?
    >
    > Regards, mark
    >


    You should look into the arts of concurrent programming, and
    specifically barrier synchronization.

    -Deniz Dogan
     
    Deniz Dogan, Nov 12, 2006
    #2
    1. Advertising

  3. mark

    Daniel Dyer Guest

    On Sun, 12 Nov 2006 13:58:23 -0000, mark <> wrote:

    > Hello,
    >
    > I have constructed several threads in my application (it is such that
    > some threads start other threads, etc.). Now I would like to have a
    > possibility to execute some actions just when all the threads finished
    > (i.e. go out from the run function). Is there any nice way to do it?
    >
    > Regards, mark


    Depending on how your threads are arranged, you can use a CountdownLatch
    or a CyclicBarrier from the java.util.concurrent package.

    Dan.

    --
    Daniel Dyer
    http://www.uncommons.org
     
    Daniel Dyer, Nov 12, 2006
    #3
  4. mark wrote:
    > Hello,
    >
    > I have constructed several threads in my application (it is such that
    > some threads start other threads, etc.). Now I would like to have a
    > possibility to execute some actions just when all the threads finished
    > (i.e. go out from the run function). Is there any nice way to do it?
    >
    > Regards, mark
    >


    While you could use general barrier techniques, there may be a simple
    alternative for your specific situation. Once the threads in question
    have been created, pass a list of references to them to a additional
    "join" thread.

    The "join" thread just calls each Thread object's join method. When the
    last join call completes, all the threads have finished their run
    methods, and the "join" thread executes the "some actions".

    The "join" thread can be the thread that created them if it has no other
    work it needs to do afterwards.

    You need the general barrier approach if you need the "some actions" to
    run in the individual threads after each has completed the substance of
    its work but before the actual return.

    Patricia
     
    Patricia Shanahan, Nov 12, 2006
    #4
  5. mark

    mark Guest

    Hello,

    > Depending on how your threads are arranged, you can use a CountdownLatch
    > or a CyclicBarrier from the java.util.concurrent package.


    Thank you for your quick answer. I have looked at both of the classes
    and it seems that both are inappropriate for my case. CountdownLeach is
    not good, because at the beginning I do not know the number of the
    created threads (that number can changes depending on the execution of
    the threads). Cyclic barrier is also not good, because I just want to
    check the situation when the thread finish (I am not going to resume it
    again) so using it I think will make java to keep every thread running
    and what I want is just to allow the garbage collector to remove them
    just to create a space for a new threads. If I am wrong please tell me.

    Regards, mark
     
    mark, Nov 12, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elizabeth Harmon

    Monitoring a Web Page request Thread?

    Elizabeth Harmon, Nov 24, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    370
    Alvin Bruney
    Nov 30, 2003
  2. Tom Davies

    Monitoring thread stalls

    Tom Davies, Oct 18, 2003, in forum: Java
    Replies:
    3
    Views:
    881
    Robert Olofsson
    Oct 18, 2003
  3. sayoyo
    Replies:
    3
    Views:
    1,275
    sayoyo
    Feb 16, 2004
  4. Replies:
    2
    Views:
    367
  5. Nagesh
    Replies:
    1
    Views:
    124
    Bob Barrows
    Jul 28, 2003
Loading...

Share This Page