Java异步代码

    // 异步操作
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,
            1,
            0L,
            TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<>(2),
            new ThreadPoolExecutor.AbortPolicy());
    CompletableFuture.runAsync(() -> {
        try {
            // 这里填写需要异步处理的代码方法
        } catch (Exception e) {
            e.printStackTrace();
        }
    }, threadPoolExecutor);
    threadPoolExecutor.shutdown();

版权声明:本文为weixin_51291483原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。