Skip to content

Commit

Permalink
Merge pull request #167 from epickrram/master
Browse files Browse the repository at this point in the history
[Java] Make synchronisation around shutdown latches more robust
  • Loading branch information
mjpt777 committed Feb 15, 2019
2 parents dd098f3 + bc9d490 commit bfdc6bd
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ShutdownSignalBarrier
*/
public ShutdownSignalBarrier()
{
synchronized (this)
synchronized (LATCHES)
{
LATCHES.add(latch);
}
Expand All @@ -58,19 +58,31 @@ public ShutdownSignalBarrier()
*/
public void signal()
{
synchronized (this)
synchronized (LATCHES)
{
LATCHES.remove(latch);
latch.countDown();
}
}

/**
* Programmatically signal all awaiting threads.
*/
public void signalAll()
{
synchronized (LATCHES)
{
LATCHES.forEach(CountDownLatch::countDown);
LATCHES.clear();
}
}

/**
* Remove the barrier from the shutdown signals.
*/
public void remove()
{
synchronized (this)
synchronized (LATCHES)
{
LATCHES.remove(latch);
}
Expand Down

0 comments on commit bfdc6bd

Please sign in to comment.