• Post Reply Bookmark Topic Watch Topic
  • New Topic

linking concurrent threads

 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on some legacy code that spins off several threads and waits until they all finish or exceed a time limit before proceeding forward. IT is written in Java 1.2 style syncing on an object etc.

Is there any easier way to do this, say using an Executor or ExecutorService? I have reviewed these classes but I cannot figure out how to accomplish the same thing.

Thank you
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cyclic Barrier

this might be of some help?

Regards
Vyas, Anirudh
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reviewed the doc at the link but I do not understand how to use it in my case. Would you please elaborate.

Does anyone else know how to do this with the ExecutorService?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With ExecutorService, you can just use the invokeAll() method - the one with three parameters, which allows you to specify a timeout. The method won't return until each task either completes or times out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!