• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 42
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 213
10
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 213
10
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
All of the following truths are shameless lies. But what about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic