// 1.采用newCachedThreadPool创建线程池 29 @Delegate 30 public ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); 31 32 //2.采用newFixedThreadPool创建线程池 33 @Delegate 34 public ExecutorService service = Executors.newFixedThreadPool(3); 35 36 //3.采用newScheduledThreadPool 创建一个定长线程池 支持定时及周期性任务执行。 37 // 使用方法: ThreadUtil.getInstance().schedule(new TestThread(),3, TimeUnit.SECONDS); 38 @Delegate 39 public ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(2); 40 41 42 //4.采用newSingleThreadExecutor 创建一个单线程化的线程池 43 @Delegate 44 public ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();
java创建线程池的方式
最新推荐文章于 2024-07-18 13:49:42 发布