package com.main; import cn.hutool.core.date.DateUtil; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Test { public static void main(String[] args) { ExecutorService executorService = Executors.newSingleThreadExecutor(); long now = DateUtil.current(true); System.out.println("开始执行时间:" + now); executorService.submit(Test::loopHello); long now2 = DateUtil.current(true); System.out.println("结束执行时间:" + now2); System.out.println("总执行时间:" + (now2 - now)); } private static void loopHello() { var i=0; while (i< 1000000000) { i++; sayHello(); } } private static Integer sayHello() { var b = 1; var a = 22; return a + b; } } 开始执行时间:264803974827800 结束执行时间:264804026950899 总执行时间:52123099