Ted Yu
2014-01-26 16:50:10 UTC
Hi,
Suppose one class has two latches:
private volatile CountDownLatch safePointAttainedLatch = new CountDownLatch(1);
privatevolatileCountDownLatch safePointReleasedLatch= newCountDownLatch(1);
And this method:
/**
* @return True is this is a 'cocked', fresh instance, and not one that has already fired.
*/
boolean isCocked() {
return this.safePointAttainedLatch.getCount() > 0 &&
this.safePointReleasedLatch.getCount() > 0;
}
There is a chance that safePointAttainedLatch is initialized while the other is not.
What's a better way to implement isCocked() ?
Thanks
Suppose one class has two latches:
private volatile CountDownLatch safePointAttainedLatch = new CountDownLatch(1);
privatevolatileCountDownLatch safePointReleasedLatch= newCountDownLatch(1);
And this method:
/**
* @return True is this is a 'cocked', fresh instance, and not one that has already fired.
*/
boolean isCocked() {
return this.safePointAttainedLatch.getCount() > 0 &&
this.safePointReleasedLatch.getCount() > 0;
}
There is a chance that safePointAttainedLatch is initialized while the other is not.
What's a better way to implement isCocked() ?
Thanks