<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 ゞ沉默是金ゞ 閱讀(772) 評(píng)論(0)  編輯  收藏 所屬分類: Java SE
    主站蜘蛛池模板: 一本色道久久88—综合亚洲精品| 一级女人18毛片免费| 亚洲欧美日韩中文二区| 亚洲AV日韩AV鸥美在线观看| 国产免费无遮挡精品视频| 亚洲欧洲日本精品| 久久久久噜噜噜亚洲熟女综合| 免费看香港一级毛片| 国产在线jyzzjyzz免费麻豆| 花蝴蝶免费视频在线观看高清版 | 国产精品免费在线播放| 亚洲色丰满少妇高潮18p| 亚洲欧洲国产成人精品| 亚洲午夜久久影院| 亚洲乱码中文字幕久久孕妇黑人| 免费a级毛片无码av| 四虎成人免费观看在线网址| 国产精品成人观看视频免费| 99久久综合精品免费| 可以免费观看的毛片| 最近免费中文字幕MV在线视频3| 无码精品人妻一区二区三区免费 | 国产三级电影免费观看| 女人被男人躁的女爽免费视频| 精品久久久久国产免费| 亚洲一区二区三区免费视频| 久久久久久夜精品精品免费啦| 日本黄色动图免费在线观看| 无码国产精品一区二区免费16| 日本免费中文字幕| 在线美女免费观看网站h| 久久午夜夜伦鲁鲁片免费无码影视| 久久国产乱子伦精品免费一| 污污网站18禁在线永久免费观看| 免费日本一区二区| 久久午夜羞羞影院免费观看| 91高清免费国产自产| 久久久久久国产a免费观看黄色大片| 免费精品国产自产拍在 | 亚洲熟妇av午夜无码不卡| 亚洲一区二区三区高清在线观看 |