...
|
...
|
@@ -13,29 +13,29 @@ import com.yoho.search.service.downgrade.IDowngrade; |
|
|
* @author hugufei
|
|
|
*/
|
|
|
public class AutoDownGradeByOverTime implements IDowngrade {
|
|
|
|
|
|
private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
|
|
private ScheduledExecutorService scheduledExecutorService;
|
|
|
private AtomicInteger overTimeCount = new AtomicInteger(0);// 当前超时次数
|
|
|
private int overTimeThreshold;// 超时次数阀值
|
|
|
|
|
|
private int lastPeroidOverTime = 0;//上一个时间段的超时次数
|
|
|
private int lastPeroidOverTime = 0;// 上一个时间段的超时次数
|
|
|
|
|
|
public AutoDownGradeByOverTime(int periodInSecond,TimeUnit timeUnit,int overTimeThreshold) {
|
|
|
public AutoDownGradeByOverTime(int periodInSecond, TimeUnit timeUnit, int overTimeThreshold) {
|
|
|
this.overTimeThreshold = overTimeThreshold;
|
|
|
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
scheduledExecutorService.scheduleAtFixedRate(new ClearOverTimeCount(), 1, periodInSecond, timeUnit);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public boolean needDowngrade() {
|
|
|
int overTime = Math.max(lastPeroidOverTime, overTimeCount.intValue());
|
|
|
return overTime> overTimeThreshold;
|
|
|
return overTime > overTimeThreshold;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void tryDowngrade() {
|
|
|
overTimeCount.incrementAndGet();
|
|
|
}
|
|
|
|
|
|
|
|
|
class ClearOverTimeCount implements Runnable {
|
|
|
@Override
|
|
|
public void run() {
|
...
|
...
|
|