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

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

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

    posts - 495,  comments - 11,  trackbacks - 0

    顧名思義:同步任務是指事情需要一件一件的做,做完當前的任務,才能開始做下一任務;異步任務是指做當前任務的同時,后臺還可以在執行其他任務,可理解為可同時執行多任務,不必一件一件接著去做,下面開始上例子了

    1.同步任務

    /*
    ?* @(#)SyncTaskExecutorTest.java?? ?2011-4-27
    ?*
    ?* Copyright (c) 2011. All Rights Reserved.
    ?*
    ?*/

    package org.jsoft.opensource.demos.spring.task;

    import org.junit.Test;
    import org.springframework.core.task.SyncTaskExecutor;

    /**
    ?* Spring同步任務處理
    ?*
    ?* @author <a href="mailto:hongyuan.czq@taobao.com">Gerald Chen</a>
    ?* @version $Id: SyncTaskExecutorTest.java,v 1.1 2011/05/30 08:58:07 gerald.chen Exp $
    ?*/
    public class SyncTaskExecutorTest {

    ?? ?@Test
    ?? ?public void test() throws InterruptedException {
    ?? ??? ?SyncTaskExecutor executor = new SyncTaskExecutor();
    ?? ??? ?executor.execute(new OutThread());
    ?? ??? ?System.out.println("Hello, World!");
    ?? ??? ?Thread.sleep(10000 * 1000L);
    ?? ?}
    ?? ?
    ?? ?static class OutThread implements Runnable {

    ?? ??? ?public void run() {
    ?? ??? ??? ?for (int i = 0; i < 1000; i++) {
    ?? ??? ??? ??? ?System.out.println(i + " start ...");
    ?? ??? ??? ??? ?try {
    ?? ??? ??? ??? ??? ?Thread.sleep(2 * 1000L);
    ?? ??? ??? ??? ?} catch (InterruptedException e) {
    ?? ??? ??? ??? ??? ?// TODO Auto-generated catch block
    ?? ??? ??? ??? ??? ?e.printStackTrace();
    ?? ??? ??? ??? ?}
    ?? ??? ??? ?}
    ?? ??? ?}
    ?? ??? ?
    ?? ?}

    }

    必須在線程任務執行完畢之后,"Hello,World!"才會被打印出來

    2.異步任務

    ?/*
    ?* @(#)AsyncTaskExecutorTest.java?? ?2011-4-27
    ?*
    ?* Copyright (c) 2011. All Rights Reserved.
    ?*
    ?*/

    package org.jsoft.opensource.demos.spring.task;

    import org.junit.Test;
    import org.springframework.core.task.AsyncTaskExecutor;
    import org.springframework.core.task.SimpleAsyncTaskExecutor;

    /**
    ?* Spring異步任務處理
    ?*
    ?* @author <a href="mailto:hongyuan.czq@taobao.com">Gerald Chen</a>
    ?* @version $Id: AsyncTaskExecutorTest.java,v 1.1 2011/05/30 08:58:07 gerald.chen Exp $
    ?*/
    public class AsyncTaskExecutorTest {

    ?? ?@Test
    ?? ?public void test() throws InterruptedException {
    ?? ??? ?AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("sys.out");
    ?? ??? ?executor.execute(new OutThread(), 50000L);
    ?? ??? ?System.out.println("Hello, World!");
    ?? ??? ?Thread.sleep(10000 * 1000L);
    ?? ?}
    ?? ?
    ?? ?static class OutThread implements Runnable {

    ?? ??? ?public void run() {
    ?? ??? ??? ?for (int i = 0; i < 100; i++) {
    ?? ??? ??? ??? ?System.out.println(i + " start ...");
    ?? ??? ??? ??? ?try {
    ?? ??? ??? ??? ??? ?Thread.sleep(2 * 1000L);
    ?? ??? ??? ??? ?} catch (InterruptedException e) {
    ?? ??? ??? ??? ??? ?// TODO Auto-generated catch block
    ?? ??? ??? ??? ??? ?e.printStackTrace();
    ?? ??? ??? ??? ?}
    ?? ??? ??? ?}
    ?? ??? ?}
    ?? ??? ?
    ?? ?}
    }

    "Hello,World!"被正常打印出來,線程任務在后臺靜靜地執行.

    ?

    關鍵詞:JAVA?? Spring?? 任務?? 同步?? 異步??? 軟件工程師?? 程序員?? 編程

    ?

    posted on 2011-06-08 20:53 jadmin 閱讀(763) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲欧洲国产成人精品| 亚洲AV无码久久精品蜜桃| 亚洲av无码久久忘忧草| 老汉精品免费AV在线播放| 亚洲天堂一区二区| 久久免费看黄a级毛片| 亚洲一区二区三区免费在线观看 | 好爽好紧好大的免费视频国产| 亚洲二区在线视频| 成年女人喷潮毛片免费播放| 亚洲精品久久久久无码AV片软件| 免费看的黄色大片| 四虎精品成人免费视频| 亚洲伊人久久大香线蕉综合图片| 最近的2019免费中文字幕| 久久久无码精品亚洲日韩按摩 | 亚洲AV无码一区二区三区鸳鸯影院| 午夜小视频免费观看| 日韩久久无码免费毛片软件| 久久影院亚洲一区| 99久热只有精品视频免费看 | 亚洲福利视频网址| 青青青国产免费一夜七次郎 | 浮力影院第一页小视频国产在线观看免费| 亚洲av成人一区二区三区观看在线| 国产zzjjzzjj视频全免费| 国产免费内射又粗又爽密桃视频| 亚洲高清专区日韩精品| 曰曰鲁夜夜免费播放视频| 亚洲av无码专区首页| 亚洲国产成人高清在线观看| 香蕉97超级碰碰碰免费公| 亚洲AV成人精品日韩一区| 亚洲欧洲日产国码av系列天堂| **aaaaa毛片免费| 美女露100%胸无遮挡免费观看| 亚洲男同帅GAY片在线观看| 日本成年免费网站| 亚洲日韩在线观看免费视频| 亚洲性猛交xx乱| 亚洲国产中文字幕在线观看|