package com.highdatas.mdm.util.pool;
|
|
import com.highdatas.mdm.util.Constant;
|
import com.highdatas.mdm.util.DbUtils;
|
import org.springframework.beans.factory.annotation.Value;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.Date;
|
|
/**
|
* @author kimi
|
* @description
|
* @date 2020-04-14 11:42
|
*/
|
|
|
public abstract class PriorityTask implements Runnable, Comparable<PriorityTask>{
|
@Value("${pool.coefficient}")
|
Integer cntCoefficient;
|
@Value("${pool.timeout}")
|
Integer timeout;
|
protected Long prority;
|
protected volatile MqEntity mqEntity;
|
protected int cnt;
|
protected Date time;
|
protected Date endTime;
|
protected HttpServletResponse response;
|
|
public MqEntity getMqEntity() {
|
return mqEntity;
|
}
|
|
public PriorityTask(MqEntity mqEntity, int cnt, Date time) {
|
this.mqEntity = mqEntity;
|
calPrority();
|
calEndTime();
|
}
|
|
public PriorityTask(MqEntity mqEntity) {
|
this.mqEntity = mqEntity;
|
}
|
|
public void calEndTime() {
|
long time = this.time.getTime();
|
if (timeout == null) {
|
timeout = 3000000;
|
}
|
long l = time + timeout;
|
this.endTime = new Date(l);
|
}
|
|
public void calPrority() {
|
long basePrority = DbUtils.getDistanceTime2Long(DbUtils.getDateByEnd(), this.time) / 1000;
|
if (cntCoefficient == null) {
|
//默认系数50
|
cntCoefficient = Constant.cntCoefficient;
|
}
|
int val = cnt * cntCoefficient;
|
basePrority += val;
|
this.prority = basePrority;
|
}
|
|
|
public int getCnt() {
|
return cnt;
|
}
|
|
public Date getEndTime() {
|
return endTime;
|
}
|
|
public Date getTime() {
|
return time;
|
}
|
|
|
public PriorityTask(MqEntity mqEntity, long prority) {
|
this.prority = prority;
|
this.mqEntity = mqEntity;
|
}
|
|
public void setCnt(int cnt) {
|
this.cnt = cnt;
|
calPrority();
|
}
|
|
public void setTime(Date time) {
|
this.time = time;
|
calPrority();
|
calEndTime();
|
}
|
|
public long getPrority() {
|
return prority;
|
}
|
|
@Override
|
public abstract void run();
|
|
|
@Override
|
public int compareTo(PriorityTask o) {
|
return prority.compareTo(o.getPrority());
|
}
|
|
|
}
|