<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<?> submit( Runnable r )
    Today in part 4 of the series we will talk about submission of runnable task via executor service. This method can be very beneficial if someone wants to upgrade legacy code from 1.4 to 1.5 onwards.
    As per JAVA version 6.0, ExecutorService Interface has following method -
    Future< ? >  submit( Runnable r ) 
      > Submits a Runnable task for execution and returns a Future representing that task.
      > This method will return NULL on successful completeion of the process, otherwise result will not be null.


    Lets start with Runnable task - As we  know that Runnable interface has following method - public void run()
    So when we say - ExecutorService.submit(Runnable Task) --> It starts a new stack starting with run method of runnable task, but as run method can not return any value so does future object. Due to this reason the signature of submit(Runnable r) is Future< ? >.
    ? --> means anything that extends Object, has no lower limit

    package com.jovialjava.blog.threads;

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

    public class RunnableExample {
        
        
    private static final ExecutorService executorPool=Executors.newFixedThreadPool(2);
        
        
    public static void main(String[] args) {
            RunnableTask_1 task_1 
    = new RunnableTask_1();
            RunnableTask_2 task_2 
    = new RunnableTask_2();
            
            
    /**
             * Submit the first task
             
    */
            Future
    <?> fut_1 = executorPool.submit(task_1);
            Future
    <?> fut_2 = executorPool.submit(task_2);
            
            
    try{
                
    if(fut_1.get() == null){
                    System.out.println(
    "TASK 1 completed SUCCESSFULLY");
                }
                
    if(fut_2.get() == null){
                    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 RunnableTask_1 implements Runnable{
            
    public void run()throws NullPointerException{
                System.out.println(
    "Hi, Inside Runnable Task 1");            
            }        

        }
        
        
    /**
         * This task will result in error.
         
    */
        
    public static class RunnableTask_2 implements Runnable{
            
    public void run()throws NullPointerException{
                System.out.println(
    "Hi, Inside Runnable Task 2");
                
    throw new IllegalStateException("Runnable Task Exception");
            }        

        }
    }
    posted on 2012-08-06 10:33 ゞ沉默是金ゞ 閱讀(773) 評論(0)  編輯  收藏 所屬分類: Java SE
    主站蜘蛛池模板: 亚洲精品人成无码中文毛片| 日韩电影免费在线| 国产AV无码专区亚洲AV漫画| 亚洲成av人片在线天堂无| 18禁无遮挡无码网站免费| 香蕉大伊亚洲人在线观看| 99久久99这里只有免费费精品| 亚洲成人福利在线| 日韩av无码成人无码免费| 亚洲女女女同性video| 浮力影院第一页小视频国产在线观看免费| 学生妹亚洲一区二区| 国产一精品一aⅴ一免费| 老司机午夜免费视频| 亚洲午夜无码片在线观看影院猛| caoporn成人免费公开| 亚洲Av熟妇高潮30p| 在线免费观看亚洲| 亚洲午夜无码毛片av久久京东热| 亚洲中文无码亚洲人成影院| 成人看的午夜免费毛片| 国产精品久久久久久亚洲小说| 四虎影视在线永久免费看黄| 成人无码精品1区2区3区免费看| 亚洲精品~无码抽插| 99久久精品免费精品国产| 亚洲一区二区三区高清不卡| 国产成人青青热久免费精品| 亚洲国产免费综合| 久久久久亚洲AV无码专区首JN| 成年在线观看免费人视频草莓| 无码毛片一区二区三区视频免费播放| 亚洲精品国产精品乱码视色| 亚洲免费闲人蜜桃| 午夜在线亚洲男人午在线| 国产亚洲精品观看91在线| 免费毛片在线看片免费丝瓜视频 | 久久久亚洲AV波多野结衣 | 亚洲?v无码国产在丝袜线观看| 99re6在线视频精品免费| 33333在线亚洲|