<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
    主站蜘蛛池模板: 亚洲国产美女精品久久久| 春暖花开亚洲性无区一区二区| 久久久久亚洲精品影视| 亚洲电影在线免费观看| 无忧传媒视频免费观看入口| 最好看的中文字幕2019免费| 国产不卡免费视频| 亚洲无人区视频大全| 两性色午夜免费视频| 大学生美女毛片免费视频| 国产V亚洲V天堂无码久久久| 九九精品国产亚洲AV日韩| 四虎成人免费影院网址| 黄色毛片免费观看| 国产1024精品视频专区免费| 亚洲日韩小电影在线观看| 亚洲AV永久无码精品一福利| 免费播放一区二区三区| 国产成人免费A在线视频| 亚洲视频在线观看地址| 成人无码视频97免费| 亚洲αv久久久噜噜噜噜噜| 日本特黄特色AAA大片免费| 亚洲第一区在线观看| 亚洲精品无码成人片久久不卡| 久久精品无码专区免费东京热| 亚洲国产综合精品| 免费无码又爽又刺激毛片| 亚洲制服中文字幕第一区| 中文字幕一区二区三区免费视频| 亚洲国产成人片在线观看| 皇色在线视频免费网站| 亚洲精品无码久久久久久久 | 亚洲人成黄网在线观看| 暖暖免费日本在线中文| 亚洲码国产精品高潮在线| 成人黄色免费网站| 亚洲制服丝袜在线播放| 国产成人免费a在线资源| 国内精品免费在线观看| 国产亚洲精品精华液|