<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
    主站蜘蛛池模板: 亚洲免费观看视频| 国产成人在线观看免费网站 | 精品久久久久久亚洲精品| 午夜爱爱免费视频| 久久精品免费网站网| 91亚洲精品第一综合不卡播放| 成人免费无码大片a毛片软件 | 免费在线观影网站| 精品丝袜国产自在线拍亚洲| va亚洲va日韩不卡在线观看| 久久国产精品免费视频| 精品久久久久久亚洲中文字幕| 亚洲人成网站在线播放影院在线| 性感美女视频免费网站午夜| 国产日韩AV免费无码一区二区| 亚洲综合在线一区二区三区| 亚洲中文字幕无码久久精品1| 在线观看av永久免费| 国产性生大片免费观看性| 国产成人精品日本亚洲专区6| 亚洲人成网7777777国产| 色妞WWW精品免费视频| 国产午夜精品免费一区二区三区| 亚洲精品女同中文字幕| 日韩精品一区二区亚洲AV观看| 亚洲VA综合VA国产产VA中| 100000免费啪啪18免进| 天黑黑影院在线观看视频高清免费| 亚洲精品乱码久久久久蜜桃| 亚洲黄色免费网址| 亚洲欧洲精品无码AV| 国产一精品一aⅴ一免费| 国拍在线精品视频免费观看| 日韩免费电影网址| 无码精品人妻一区二区三区免费| 亚洲熟女综合色一区二区三区| 久久精品国产亚洲AV无码娇色| 国产精品亚洲A∨天堂不卡| 亚洲AV无码一区二三区| 免费黄色毛片视频| 日韩欧毛片免费视频|