首页>代码>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日
最近浏览更多
Murmure  LV2 2023年12月21日
fellowfun  LV12 2023年11月15日
szf123  LV12 2023年5月30日
wadadd  LV7 2022年9月4日
要保持微笑  LV4 2022年7月5日
aqin_qin  LV1 2022年6月5日
364502984  LV18 2022年6月2日
woaini12788  LV7 2022年1月13日
刘毅 2021年9月29日
暂无贡献等级
zz1230012300  LV11 2021年9月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友