多线程异步查询

ExecutorService detailExecutorService = Executors.newFixedThreadPool(500);
        protected static final ExecutorService executorService = Executors.newScheduledThreadPool(2 * 2 + 1, Executors.defaultThreadFactory());
            
        CountDownLatch latch = new CountDownLatch(3);
        

        executorService.submit(() -> {
            try {
            
                method 1 ...
                
            } finally {
                latch.countDown();
            }
        });


        executorService.submit(() -> {
            try {
            
                method 2 ...
                
            } finally {
                latch.countDown();
            }
        });
        
        executorService.submit(() -> {
            try {
            
                method 3 ...
                
            } finally {
                latch.countDown();
            }
        });

        try {
            latch.await(5L, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            logger.error("InterruptedException happened=", e);
        }

猜你喜欢

转载自www.cnblogs.com/wanhua-wu/p/9368144.html