import java.util.concurrent.*;
public class Silence {public static void main(String[] args) {ThreadPoolExecutor thread = new ThreadPoolExecutor(5,10,60,TimeUnit.SECONDS,new ArrayBlockingQueue<>(10),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());for (int i = 0; i < 8; i++) {while (true) {int activeCount = thread.getActiveCount();int maximumPoolSize = thread.getMaximumPoolSize();if (activeCount < maximumPoolSize) {thread.submit(() -> {System.out.println("线程提交");try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}});break;}}}thread.shutdown();int activeCount = thread.getActiveCount();System.out.println("返回正在执行任务的线程的大概数量:" + activeCount);
BlockingQueue<Runnable> queue = thread.getQueue();System.out.println("队列排队的任务个数:" + queue.size());}
}