Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Thread-end monitoring

Thread view: 
mark - 12 Nov 2006 13:58 GMT
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
Deniz Dogan - 12 Nov 2006 14:00 GMT
> Hello,
>
[quoted text clipped - 4 lines]
>
> Regards, mark

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

-Deniz Dogan
Daniel Dyer - 12 Nov 2006 14:24 GMT
> Hello,
>
[quoted text clipped - 4 lines]
>
> Regards, mark

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

Dan.

Signature

Daniel Dyer
http://www.uncommons.org

mark - 12 Nov 2006 15:06 GMT
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
Patricia Shanahan - 12 Nov 2006 15:04 GMT
> Hello,
>
[quoted text clipped - 4 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.