Tags

links:
– javadoc
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html
http://www.ibm.com/developerworks/library/j-5things5/
http://www.ibm.com/developerworks/java/library/j-5things4/index.html

summary:
– ExecutorService extends Executor
– Executor has only 1 method while ExecutorService has many more
– Executor.execute(Runnable command), it executes the given command at some time in the future.
– execute vs submit, submit can return value thru Future
– e.g executing a list of Callables all together,
ExecutorService taskExecutor = Executors.newFixedThreadPool(4);
List <tasks>;
List <futures> = taskExecutor.invokeAll(tasks);
– Thread object creation could be expensive, so Executor abstraction hides and takes care of details for caller
– HeartBeat example using ScheduledExecutorService,

    public static void main(String[] args)
    {
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
        Runnable pinger = new Runnable() {
            public void run() {
                System.out.println("PING!");
            }
        };
        ses.scheduleAtFixedRate(pinger, 3, 3, TimeUnit.SECONDS);
    }
Advertisements