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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
    //實例一,這里面用到了信號量Semaphore和FutureTask

    package net.abin.lee.mythread.callable;

    import java.util.concurrent.Callable;
    import java.util.concurrent.Semaphore;
    import java.util.concurrent.locks.Lock;
    import java.util.concurrent.locks.ReentrantReadWriteLock;

    public class FutureGo implements Callable<String> {
     private String message;
     private static final Semaphore semaphore=new Semaphore(3);
     private final ReentrantReadWriteLock rwl=new ReentrantReadWriteLock();
     public FutureGo(String message) {
      this.message = message;
     }

     public String call() throws InterruptedException {
      semaphore.acquire();
      Lock read=rwl.readLock();
      Lock write=rwl.readLock();
      read.lock();  
      System.out.println("message"+message+",Name"+Thread.currentThread().getName()+"進來了");
      read.unlock();
      write.lock();
      String result=message+"你好!";
      Thread.sleep(1000);
      System.out.println("message"+message+"Name"+Thread.currentThread().getName()+"離開了");
      write.unlock();
      semaphore.release();
      return result;
     }
    }



    //FutureTaskTest.java

    package net.abin.lee.mythread.callable;

    import java.util.concurrent.Callable;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.FutureTask;

    public class FutureTaskTest {
     public static void main(String[] args) throws InterruptedException,
       ExecutionException {
      Callable<String> go = new FutureGo("abin");
      FutureTask<String> task = new FutureTask<String>(go);
      ExecutorService executor = Executors.newCachedThreadPool();
      if (!executor.isShutdown()) {
       executor.execute(task);
      }
      String result = "";
      if (!task.isDone()) {
       result = (String) task.get();
       System.out.println("result=" + result);
      }
       executor.shutdown();
     }

    }






    //實例一,這里面用到了信號量Semaphore和FutureTask

    posted on 2013-01-10 14:17 abin 閱讀(671) 評論(0)  編輯  收藏 所屬分類: JavaMultithread
    主站蜘蛛池模板: 天堂在线免费观看中文版| 久久精品国产免费观看| 亚洲国产成人久久综合碰| 亚洲国产精品无码观看久久| 成人毛片手机版免费看| 亚洲国产视频久久| 精品少妇人妻AV免费久久洗澡| 一级一看免费完整版毛片| www.91亚洲| APP在线免费观看视频| 亚洲精品狼友在线播放| 特级无码毛片免费视频尤物| 国产亚洲日韩在线三区| 久久午夜无码免费| 亚洲欧洲精品久久| 四虎成人免费网址在线| 日韩在线观看视频免费| 亚洲热线99精品视频| 99久久久国产精品免费牛牛| 精品亚洲成A人无码成A在线观看| 成人午夜免费视频| 亚洲成AV人片在线播放无码| 亚洲一级毛片免费观看| 亚洲成年网站在线观看| 国产一区二区三区在线免费 | 亚洲区小说区图片区| 一区二区三区免费在线观看| 在线亚洲97se亚洲综合在线| 亚洲免费视频观看| 狠狠入ady亚洲精品| 亚洲精品午夜无码电影网| 很黄很色很刺激的视频免费| 人人公开免费超级碰碰碰视频| 四虎免费大片aⅴ入口| sihu国产精品永久免费| 亚洲老熟女@TubeumTV| 一本久久综合亚洲鲁鲁五月天 | 亚洲AV本道一区二区三区四区| 亚洲欧美日韩综合久久久久| 99久久免费观看| 亚洲精品欧美综合四区|