org.bdware.doip.cluster.entity.RequestPackIntf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
The newest version!
package org.bdware.doip.cluster.entity;
/*
* 通过这个优先级来判断任务的执行
*
* */
import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public abstract class RequestPackIntf implements Comparable, Runnable {
public static ExecutorService taskPool =
new ThreadPoolExecutor(
8, // corePoolSize (number of threads to keep in the pool)
16, // maximumPoolSize (maximum number of threads allowed in the pool)
0L, TimeUnit.MILLISECONDS, // keepAliveTime (idle threads will be terminated after this duration)
new PriorityBlockingQueue<>(), // workQueue (a queue to hold tasks until they are executed)
//new LinkedBlockingQueue<>(),
r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
);
public abstract long getPriority();
@Override
public int compareTo(RequestPackIntf o) {
long val = getPriority() - o.getPriority();
return (int) val;
}
public void execute() {
taskPool.execute(this);
}
}