多线程查询优化
Semaphore semaphore = new Semaphore(nThread); //创建线程池 ThreadPoolExecutor executor = new ThreadPoolExecutor(2, nThread, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(30), new ThreadFactoryBuilder().setNameFormat("线程名称").build(), new ThreadPoolExecutor.AbortPolicy()); for (T number : list) { try { semaphore.acquire(); executor.execute(() -> { //此处可以放入待处理的业务 System.out.println("number:" + number); semaphore.release(); }); } catch (InterruptedException e) { } } executor.shutdown();