Authored by 胡古飞

fix AutoDownGradeByOverTime

@@ -13,29 +13,29 @@ import com.yoho.search.service.downgrade.IDowngrade; @@ -13,29 +13,29 @@ import com.yoho.search.service.downgrade.IDowngrade;
13 * @author hugufei 13 * @author hugufei
14 */ 14 */
15 public class AutoDownGradeByOverTime implements IDowngrade { 15 public class AutoDownGradeByOverTime implements IDowngrade {
16 -  
17 - private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); 16 +
  17 + private ScheduledExecutorService scheduledExecutorService;
18 private AtomicInteger overTimeCount = new AtomicInteger(0);// 当前超时次数 18 private AtomicInteger overTimeCount = new AtomicInteger(0);// 当前超时次数
19 private int overTimeThreshold;// 超时次数阀值 19 private int overTimeThreshold;// 超时次数阀值
20 -  
21 - private int lastPeroidOverTime = 0;//上一个时间段的超时次数 20 + private int lastPeroidOverTime = 0;// 上一个时间段的超时次数
22 21
23 - public AutoDownGradeByOverTime(int periodInSecond,TimeUnit timeUnit,int overTimeThreshold) { 22 + public AutoDownGradeByOverTime(int periodInSecond, TimeUnit timeUnit, int overTimeThreshold) {
24 this.overTimeThreshold = overTimeThreshold; 23 this.overTimeThreshold = overTimeThreshold;
  24 + scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
25 scheduledExecutorService.scheduleAtFixedRate(new ClearOverTimeCount(), 1, periodInSecond, timeUnit); 25 scheduledExecutorService.scheduleAtFixedRate(new ClearOverTimeCount(), 1, periodInSecond, timeUnit);
26 } 26 }
27 - 27 +
28 @Override 28 @Override
29 public boolean needDowngrade() { 29 public boolean needDowngrade() {
30 int overTime = Math.max(lastPeroidOverTime, overTimeCount.intValue()); 30 int overTime = Math.max(lastPeroidOverTime, overTimeCount.intValue());
31 - return overTime> overTimeThreshold; 31 + return overTime > overTimeThreshold;
32 } 32 }
33 - 33 +
34 @Override 34 @Override
35 public void tryDowngrade() { 35 public void tryDowngrade() {
36 overTimeCount.incrementAndGet(); 36 overTimeCount.incrementAndGet();
37 } 37 }
38 - 38 +
39 class ClearOverTimeCount implements Runnable { 39 class ClearOverTimeCount implements Runnable {
40 @Override 40 @Override
41 public void run() { 41 public void run() {