<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 ゞ沉默是金ゞ 閱讀(806) 評論(0)  編輯  收藏 所屬分類: Java SE
    主站蜘蛛池模板: a级毛片毛片免费观看久潮| 七次郎成人免费线路视频| 69免费视频大片| 亚洲精品高清国产麻豆专区| 免费观看久久精彩视频| 亚洲AV永久无码区成人网站| 免费萌白酱国产一区二区三区 | 成人无码精品1区2区3区免费看| 日韩免费高清视频| 香港特级三A毛片免费观看| 亚洲av无码天堂一区二区三区| 牛牛在线精品观看免费正| 一级毛片直播亚洲| 成人无码区免费A∨直播| 亚洲成AV人片在线观看| aⅴ在线免费观看| 亚洲狠狠色丁香婷婷综合| 国产一区二区三区在线观看免费| 特级一级毛片免费看| 亚洲色婷婷一区二区三区| 无码国产精品一区二区免费模式| 亚洲色偷偷av男人的天堂| 成人免费视频试看120秒| 色欲aⅴ亚洲情无码AV| 久久影视综合亚洲| 99re热精品视频国产免费| 亚洲香蕉久久一区二区| 国产免费131美女视频| 97在线视频免费公开视频| 亚洲蜜芽在线精品一区| 日韩免费高清一级毛片在线| 精品熟女少妇aⅴ免费久久 | 久久亚洲精品无码aⅴ大香| 成年女性特黄午夜视频免费看| 免费的黄色的网站| 911精品国产亚洲日本美国韩国| 大香人蕉免费视频75| 中文字幕在线视频免费观看| 亚洲一区免费视频| 中文字幕在线亚洲精品| 一个人免费观看www视频在线|