All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.cluster.entity.RequestPackIntf Maven / Gradle / Ivy

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy