首页>代码>spring通过@Async注解实现异步执行Service方法并且通过Java Future对象得到执行结果>/spring-async-future-example/src/main/java/com/memorynotfound/Main.java
package com.memorynotfound; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; public class Main { public static void main(String...args) throws InterruptedException, ExecutionException { ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); MailSender mailSender = context.getBean(MailSender.class); System.out.println("about to run"); Future<Boolean> future = mailSender.sendMail(); System.out.println("this will run immediately."); Boolean result = future.get(); System.out.println("mail send result: " + result); } }
最近下载更多
wanyuan123 LV2
2021年1月5日