zoukankan      html  css  js  c++  java
  • google MoreExecutors

    import cn.hutool.core.thread.NamedThreadFactory;
    import com.google.common.util.concurrent.ListenableFuture;
    import com.google.common.util.concurrent.ListeningExecutorService;
    import com.google.common.util.concurrent.MoreExecutors;
    
    import java.util.concurrent.*;
    
    public class ThreadPool {
    
        /**
         * invoke 线程池
         */
        public static ExecutorService executorService =
                new ThreadPoolExecutor(
                        40,
                        100,
                        20L,
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue<>(50),
                        new NamedThreadFactory("mian-thread",true),
                        new ThreadPoolExecutor.CallerRunsPolicy());//超出,直接忽略
    
       public static ListeningExecutorService backgroundRefreshPools =
                MoreExecutors.listeningDecorator(executorService);
    
    
       public static void execute(Runnable runnable){
           executorService.execute(runnable);
       }
    
    
       public static <T> ListenableFuture<T> submit(Callable<T> callable){
           return backgroundRefreshPools.submit(callable);
       }
    
       public static <T> Future<T>  submitFuture(Callable<T> callable) {
           return executorService.submit(callable);
       }
    
    }
  • 相关阅读:
    杂篇章
    敲代码中遇到的小问题
    数组的运用
    java中强大的免费的集成开发环境(IDE)eclipse的使用技巧及注意事项
    流程
    博客目录
    pgk
    gogs
    github相关
    axios记录
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/15204795.html
Copyright © 2011-2022 走看看