首页>代码>spring通过@Async注解实现异步执行Service方法并且通过Java Future对象得到执行结果>/spring-async-future-example/src/main/java/com/memorynotfound/MailSender.java
package com.memorynotfound;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import java.util.concurrent.Future;

@Component
public class MailSender {

    @Async
    public Future<Boolean> sendMail() throws InterruptedException {
        System.out.println("sending mail..");
        Thread.sleep(1000 * 10);
        System.out.println("sending mail completed");
        return new AsyncResult<Boolean>(true);
    }
}
最近下载更多
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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友