加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactor自定义RejectedExecutionHandler

发布时间:2020-12-15 05:08:55 所属栏目:百科 来源:网络整理
导读:参数 reactor-core-2.0.8.RELEASE-sources.jar!/reactor/core/dispatch/ThreadPoolExecutorDispatcher.java /** * Create a new {@literal ThreadPoolExecutorDispatcher} with the given size,backlog,name,and {@link * java.util.concurrent.RejectedExec

参数

reactor-core-2.0.8.RELEASE-sources.jar!/reactor/core/dispatch/ThreadPoolExecutorDispatcher.java

/**
     * Create a new {@literal ThreadPoolExecutorDispatcher} with the given size,backlog,name,and {@link
     * java.util.concurrent.RejectedExecutionHandler}.
     *
     * @param poolSize
     *         the pool size
     * @param backlog
     *         the backlog size
     * @param threadName
     *         the name prefix to use when creating threads
     * @param rejectedExecutionHandler
     *         the {@code RejectedExecutionHandler} to use when jobs can't be submitted to the thread pool
     */
    public ThreadPoolExecutorDispatcher(int poolSize,int backlog,String threadName,BlockingQueue<Runnable> workQueue,RejectedExecutionHandler rejectedExecutionHandler) {
        super(poolSize,backlog);
        this.workQueue = workQueue;
        this.executor = new ThreadPoolExecutor(
                poolSize,poolSize,0L,TimeUnit.MILLISECONDS,workQueue,new NamedDaemonThreadFactory(threadName,getContext()),rejectedExecutionHandler
        );
    }

配置文件的size,对应ThreadPoolExecutor的corePoolSize以及maximumPoolSize

自定义ThreadPoolExecutorDispatcher

Dispatcher dispatcher = new ThreadPoolExecutorDispatcher(5,2048,"dispatcherGroup",new LinkedBlockingQueue<Runnable>(2048),new ThreadPoolExecutor.DiscardOldestPolicy());
EventBus eventBus = EventBus.create(eventBusEnv,dispatcher);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读