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

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

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

    ゞ沉默是金ゞ

    魚離不開水,但是沒有說不離開哪滴水.
    posts - 98,comments - 104,trackbacks - 0
    Future<T> submit(Callable<T> c)
    Today in next part of the series we will talk about submission of callable task via executor service. 

    As per JAVA version 6.0, ExecutorService Interface has following method -
    Future< T >  submit( callable c )
    1. Submits a Callable task for execution and returns a Future representing that task computation.
    2. Future< T > will return T on successful completion of the process, otherwise result will not be T.
    Lets start with Callable task - As we  know that Callable<T> interface has following method - public T call()
    So when we say - ExecutorService.submit(Callable Task) --> It starts a new stack starting with call method of callable task, as call method can return T so does future object. Due to this reason the signature of submit(Callable c) is Future< T >.
    T --> means anything that extends Object.
    package com.jovialjava.blog.threads;

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


    public class CallableExample {

        
    private static final ExecutorService executorPool=Executors.newFixedThreadPool(2);
        
        
    public static void main(String[] args) {
            CallableTask_1 task_1 
    = new CallableTask_1();
            CallableTask_2 task_2 
    = new CallableTask_2();
            
            
    /**
             * Submit the first task
             
    */
            Future
    <Boolean> fut_1 = executorPool.submit(task_1);
            Future
    <Boolean> fut_2 = executorPool.submit(task_2);
            
            
    try{
                
    if(fut_1.get()){
                    System.out.println(
    "TASK 1 completed SUCCESSFULLY");
                }
                
    if(fut_2.get()){
                    System.out.println(
    "TASK 2 completed SUCCESSFULLY");
                }
            }
    catch(ExecutionException e){            
                System.out.println(e.getMessage());
            }
    catch(InterruptedException e){
                System.out.println(e.getMessage());
            }
    finally{
                
    /**====VERY IMPORTANT===
                 * This is required to stop the executor pool to
                 * stop accepting new request.
                 
    */
                executorPool.shutdown();
            }

        }

        
        
    /**
         * This task will complete successfully
         
    */
        
    public static class CallableTask_1 implements Callable<Boolean>{
            
    public Boolean call()throws NullPointerException{
                System.out.println(
    "Hi, Inside Callable Task 1");
                
    return true;
            }        

        }
        
        
    /**
         * This task will result in error.
         
    */
        
    public static class CallableTask_2 implements Callable<Boolean>{
            
    public Boolean call()throws NullPointerException{
                System.out.println(
    "Hi, Inside Callable Task 2");
                
    throw new IllegalStateException("Callable Task Exception");
            }        

        }
    }
    posted on 2012-08-06 10:35 ゞ沉默是金ゞ 閱讀(797) 評論(0)  編輯  收藏 所屬分類: Java SE
    主站蜘蛛池模板: 三年片在线观看免费观看大全中国 | 日本中文一区二区三区亚洲| 亚洲精品亚洲人成在线观看麻豆| 日韩电影免费观看| 亚洲爆乳精品无码一区二区三区| 永久免费AV无码网站国产| 亚洲色爱图小说专区| 亚洲a一级免费视频| 亚洲黄色网站视频| 久草视频免费在线| 久久亚洲精品专区蓝色区| 成人免费男女视频网站慢动作 | 四虎AV永久在线精品免费观看| 亚洲AV永久无码天堂影院| 国产jizzjizz视频免费看| 美女被暴羞羞免费视频| 亚洲毛片网址在线观看中文字幕| 国产成人无码精品久久久久免费 | 亚洲AV色无码乱码在线观看| 国产一区二区三区在线免费| 一级黄色片免费观看| 亚洲AV无码专区国产乱码电影 | 美女免费视频一区二区| 久久久久亚洲精品男人的天堂| 中文字幕久精品免费视频| 久久亚洲美女精品国产精品| 在线天堂免费观看.WWW| 粉色视频在线观看www免费| 国产aⅴ无码专区亚洲av麻豆| 99久久免费精品视频| 亚洲首页国产精品丝袜| 亚洲成?Ⅴ人在线观看无码| 国产永久免费高清在线| 亚洲一本之道高清乱码| 哒哒哒免费视频观看在线www | 亚洲综合色婷婷七月丁香| 久章草在线精品视频免费观看| 亚洲国产成人精品久久| 亚洲国产精品尤物YW在线观看| 1000部啪啪毛片免费看| 无码色偷偷亚洲国内自拍|