zl程序教程

您现在的位置是:首页 >  后端

当前栏目

JAVA 异步

2023-09-11 14:19:17 时间
			//异步执行
			ExecutorService executorService = Executors.newSingleThreadExecutor();
		    CompletableFuture.runAsync(() ->{
		        System.out.println("异步线程 =====> 开始 =====> " + System.currentTimeMillis());
		        try{
		            Thread.sleep(60000);
		            
		            //跳转要执行的函数
		            calculatorAge();
		            
		        }catch (InterruptedException e){
		            e.printStackTrace();
		        }
		        System.out.println("异步线程 =====> 结束 =====> " + System.currentTimeMillis());
		    },executorService);
		    executorService.shutdown(); // 回收线程池

参考:http://t.csdn.cn/m59Ll