Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java ThreadGroup

 
sadanand munswamy
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sadanand munswamy
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In and of itself, no. A ThreadGroup simply represents a logical grouping of threads.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic