• Post Reply Bookmark Topic Watch Topic
  • New Topic

what happens if an exception is thrown by barrier action (CyclicBarrier concept)  RSS feed

 
rambabu desina
Ranch Hand
Posts: 42
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all Ranchers,

I am new to concurrent program, while reading about CyclicBarrier i have one doubt, that is what happens if an exception is thrown by barrier action (an action supplied to CyclicBarrier to run after reaching the barrier).


Thanks and regrards
Ram
 
Simon Roberts
Author
Ranch Hand
Posts: 182
9
Java Linux Netbeans IDE Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The barrier action is defined by a Runnable, which cannot throw a checked exception. It seems reasonable to expect that any unchecked exceptions must be ignored; they surely don't want to be allowed to kill the barrier's management thread

In other words, make sure you add any unchecked exception management code to your action Runnable.
 
rambabu desina
Ranch Hand
Posts: 42
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon,

Thanks for your quick reply. but i want to know if we dont write the exceprion management code in barrier action then what will happen to barrier threads.
i mean that do barrier threads continue their execution or throw the BrokenBarrierException?

Regards
Ram
 
Simon Roberts
Author
Ranch Hand
Posts: 182
9
Java Linux Netbeans IDE Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread that happens to execute the barrier action (which is one of the threads that awaits, but I don't believe it's predictable as to which) receives the unhandled exception, the others get a BrokenBarrier.

Why would you not just handle the exception in the barrier action code?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!