<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java隨記

    堅持就是勝利!

     

    sbringboot異步執行

    把需要異步執行的任務丟到統一的線程池里執行,這個想法不錯。springboot簡化這個的代碼。實現如下:

    import java.util.concurrent.Executor;
    import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.scheduling.annotation.AsyncConfigurer;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
    @Configuration
    @EnableAsync   //開啟異步任務支持
    public class TaskExcutorConfig implements AsyncConfigurer {
    @Override
    public Executor getAsyncExecutor() {
    // TODO Auto-generated method stub
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(10);
    taskExecutor.setQueueCapacity(20);
    taskExecutor.setCorePoolSize(5);
    taskExecutor.initialize();
    return taskExecutor;
    }
    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
    // TODO Auto-generated method stub
    return null;
    }

    任務類或方法

    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Service;
    //@Async 寫在這里則整個類的方法都 是異步執行
    @Service
    public class AsynTestService {
    @Async   //需要異步執行的方法
    public void asyncTest() {
    for(int i = 0; i < 10;i++) {
    System.out.println(i);
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    }

    posted on 2017-09-26 12:26 傻 瓜 閱讀(303) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(7)

    我參與的團隊

    隨筆分類

    隨筆檔案

    文章分類

    友情鏈接

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费观看黄色的网站| 久久这里只有精品国产免费10| 久久精品国产亚洲av成人| 精品一区二区三区无码免费视频| 国产亚洲sss在线播放| 免费中文字幕不卡视频| 日本免费久久久久久久网站| 亚洲色欲色欲www| 久久久久亚洲av毛片大| 美丽的姑娘免费观看在线播放 | 亚洲aⅴ无码专区在线观看春色| 亚洲成人高清在线| 97国产在线公开免费观看| 亚洲av无码兔费综合| 亚洲av福利无码无一区二区| 免费鲁丝片一级观看| 国产亚洲免费的视频看| 亚洲国产精品美女久久久久| 亚洲成色在线综合网站| 处破痛哭A√18成年片免费| 日韩a级无码免费视频| 亚洲精品第一国产综合亚AV| 亚洲AV无码国产丝袜在线观看 | 精品丝袜国产自在线拍亚洲| 亚洲毛片不卡av在线播放一区| 亚洲电影在线免费观看| 一区二区三区在线观看免费| 亚洲伦理中文字幕| 国产AV无码专区亚洲A∨毛片| 国产一级一片免费播放| 2020因为爱你带字幕免费观看全集 | 亚洲精品在线视频观看| 亚洲另类激情专区小说图片| 黄+色+性+人免费| 中文字幕手机在线免费看电影| 亚洲欧美日韩中文无线码| 亚洲国产香蕉碰碰人人| 中文字幕亚洲乱码熟女一区二区| 性xxxx视频播放免费| 114级毛片免费观看| 免费无码又爽又刺激一高潮|