美文网首页
多线程压力测试例子 - ExecutorService shut

多线程压力测试例子 - ExecutorService shut

作者: hisenyuan | 来源:发表于2018-07-13 17:04 被阅读0次
    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 shut

      本文链接:https://www.haomeiwen.com/subject/bxrspftx.html