wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Java ThreadGroup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Java ThreadGroup " Watch "Java ThreadGroup " New topic
Author

Java ThreadGroup

sadanand munswamy
Ranch Hand

Joined: Apr 10, 2012
Posts: 39
Dear Ranchers,
I have a multithreaded app, where i spawn n threads, i need to execute a method before these threads run,
and also after all of these n threads have finished running. How do I achieve it, via Thread-Group or any java1.5 compatible API.
HELP !!
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1756
    
    7

You can use a CyclicBarrier with a barrier action that execute the method call when the last thread enters it.
However the requirement of the initial method call is unclear to me. Can't you simply execute that method before spawning the threads?


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
sadanand munswamy
Ranch Hand

Joined: Apr 10, 2012
Posts: 39
Hey Jelle Klap, Many thanks for your reply, You are right, the 1st part i have called before swapping the threads,
the only issue now left is the later part. Can i achieve the same via ThreadGroup.
Please Reply
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1756
    
    7

In and of itself, no. A ThreadGroup simply represents a logical grouping of threads.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java ThreadGroup
 
Similar Threads
Reg. Threads what to do ??
Can we use thread in ejbs ?
Garbage Collector Threads
getting number of threads
YES (Yet Another Synchronization) question