HBASE-5290 [FindBugs] Synchronization on boxed primitive (Ben West)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1238693 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2012-01-31 16:52:51 +00:00
parent 093c7203e8
commit 650b321396
1 changed files with 15 additions and 6 deletions

View File

@ -36,9 +36,18 @@ public class CompactSelection {
// the actual list - this is needed to handle methods like "sublist"
// correctly
List<StoreFile> filesToCompact = new ArrayList<StoreFile>();
// number of off peak compactions either in the compaction queue or
// happening now
public static Integer numOutstandingOffPeakCompactions = 0;
/**
* Number of off peak compactions either in the compaction queue or
* happening now. Please lock compactionCountLock before modifying.
*/
static long numOutstandingOffPeakCompactions = 0;
/**
* Lock object for numOutstandingOffPeakCompactions
*/
private final static Object compactionCountLock = new Object();
// HBase conf object
Configuration conf;
// was this compaction promoted to an off-peak
@ -83,7 +92,7 @@ public class CompactSelection {
*/
public double getCompactSelectionRatio() {
double r = this.compactRatio;
synchronized(numOutstandingOffPeakCompactions) {
synchronized(compactionCountLock) {
if (isOffPeakHour() && numOutstandingOffPeakCompactions == 0) {
r = this.compactRatioOffPeak;
numOutstandingOffPeakCompactions++;
@ -104,7 +113,7 @@ public class CompactSelection {
*/
public void finishRequest() {
if (isOffPeakCompaction) {
synchronized(numOutstandingOffPeakCompactions) {
synchronized(compactionCountLock) {
numOutstandingOffPeakCompactions--;
isOffPeakCompaction = false;
}
@ -124,7 +133,7 @@ public class CompactSelection {
public void emptyFileList() {
filesToCompact.clear();
if (isOffPeakCompaction) {
synchronized(numOutstandingOffPeakCompactions) {
synchronized(compactionCountLock) {
// reset the off peak count
numOutstandingOffPeakCompactions--;
isOffPeakCompaction = false;