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

pro.jk.ejoker.common.system.wrapper.MixedThreadPoolExecutor Maven / Gradle / Ivy

There is a newer version: 3.0.7.1
Show newest version
package pro.jk.ejoker.common.system.wrapper;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 此类仅仅是包装一下让QuasarFiber能够等待线程池中的原生线程。如果没有这个需求,可以直接替换为父类ThreadPoolExecutor
* * @author kimffy * */ public class MixedThreadPoolExecutor extends ThreadPoolExecutor { public MixedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); } public MixedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); } public MixedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue, ThreadFactory threadFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); } public MixedThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); ((FutureTaskWrapper )r).release(); // 按照逻辑,这个锁在任务完成后会被解锁,预期内仅仅有这1次解锁的机会 } @Override protected RunnableFuture newTaskFor(Runnable runnable, T value) { return new FutureTaskWrapper<>(runnable, value); } @Override protected RunnableFuture newTaskFor(Callable callable) { return new FutureTaskWrapper<>(callable); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy