多线程压力测试例子 - ExecutorService shutdown() awaitTermination()

    public void testCreate() {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("hisenyuan").build();
        ExecutorService pool = new ThreadPoolExecutor(
                20,
                50,
                10000L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(10240),
                namedThreadFactory,
                new ThreadPoolExecutor.AbortPolicy());
        for (int i = 0; i < 50; i++) {
            // 需要提交的内容
            pool.execute(this::createTokenTest);
        }
        pool.shutdown();
        try {
            while (!pool.awaitTermination(500, TimeUnit.MILLISECONDS)) {
                LOGGER.debug("Waiting for terminate");
            }
        } catch (InterruptedException e) {
            LOGGER.error(e);
        }
    }

你可能感兴趣的:(多线程压力测试例子 - ExecutorService shutdown() awaitTermination())