public class IndexBinarySearch<T> { public static void main(String[] args) { ThreadPoolExecutor poolExecutor=new ThreadPoolExecutor(5, 10, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<Runnable>(2) ); List<Runnable> rlist=new ArrayList<>(); for(int i=0;i<20;i ){ rlist.add(new RunnableTest(poolExecutor)); } for(int i=0;i<20;i ){ poolExecutor.execute(rlist.get(1)); } } } class RunnableTest implements Runnable{ ThreadPoolExecutor poolExecutor; public RunnableTest( ThreadPoolExecutor poolExecutor){ this.poolExecutor=poolExecutor; } @Override public void run() { int threadSize=this.poolExecutor.getActiveCount(); int queueCurrentSize=this.poolExecutor.getQueue().size(); System.out.println(Thread.currentThread().getName() ":执行开始:" "当前线程数:" threadSize "当前队列大小:" queueCurrentSize); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
END 十期推荐 【231期】面试官:Java中 serialVersionUID 的作用是什么? 【232期】面试官:Spring的 IOC 容器比New对象究竟好在哪? 【233期】面试官:什么是耦合?解耦合的方法有哪几种? 【234期】30个 Java 集合面试必备的问题和答案 【235期】面试官:Redis的数据是存在内存里吗?谈谈Redis各种数据类型的使用场景? 【236期】面试官:线程池中多余的线程是如何回收的? 【237期】面试官:如何发现 Redis 热点 Key ,解决方案有哪些? 【238期】面试官:Redis新版本开始引入多线程,谈谈你的看法? 【239期】面试官:如何使用Redis实现电商系统的库存扣减? 【240期】面试官:你了解JVM的内存溢出吗? ? ~