<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 ゞ沉默是金ゞ 閱讀(779) 評論(0)  編輯  收藏 所屬分類: Java SE
    主站蜘蛛池模板: 精品久久久久国产免费| 亚洲精品动漫免费二区| 亚洲无码精品浪潮| 国产亚洲高清在线精品不卡| 女人张开腿给人桶免费视频| 国产日本亚洲一区二区三区| 在线观看无码的免费网站| 亚洲日本成本人观看| 国产男女性潮高清免费网站| 麻豆一区二区三区蜜桃免费| 亚洲人成色7777在线观看不卡| 免费国产va在线观看| 亚洲精品成人片在线播放| 免费一级毛片在线播放视频| 久久亚洲日韩精品一区二区三区 | 亚洲欧洲无码一区二区三区| 免费无码一区二区三区蜜桃大| 校园亚洲春色另类小说合集| 亚洲男女内射在线播放| 日韩a级无码免费视频| 亚洲精品中文字幕无乱码| 最近中文字幕无吗免费高清 | 水蜜桃亚洲一二三四在线| 久视频精品免费观看99| 亚洲欧美成aⅴ人在线观看| 日产国产精品亚洲系列| 波多野结衣免费一区视频| 亚洲av无码专区在线| www亚洲一级视频com| 国产羞羞的视频在线观看免费| 亚洲欧洲日产v特级毛片| 国产免费131美女视频| 91精品全国免费观看青青| 亚洲人妖女同在线播放| 又色又污又黄无遮挡的免费视| 两个人看的www免费| 中文字幕亚洲精品无码| 日韩亚洲国产综合久久久| 91视频免费网址| 狠狠热精品免费观看| 亚洲丝袜美腿视频|