/**
* 异步任务调度
*/
public class AsyncProxyUtil {
private static ExecutorService executor = Executors.newFixedThreadPool(10);
public static <T> CompletableFuture<T> executeAsyncTask(Supplier<T> task) {
CompletableFuture<T> future = new CompletableFuture<>();
executor.submit(() -> {
try {
T result = task.get();
future.complete(result);
} catch (Exception e) {
future.completeExceptionally(e);
}
});
return future;
}
public static void shutdown() {
executor.shutdown();
}
}
直接打点调用即可,因为是线程池管理线程所以不需要手动shutdown,当全部线程执行完毕之后jvm会自动回收
THE END
暂无评论内容