Sunday, August 30, 2015

Concurrency : Thread Executor basics

package : Java.lang.concurrent.ExecutorService

Thread Pool naming convention :pool-<N_GLOBAL_GROUP_COUNT>-thread-<M_THREAD_COUNT_WITHIN_A_GROUP>,

ExecutorService executor = Executors.newSingleThreadExecutor;
executor = Executors.newSingleThreadExecutor;//single thread size
 executor  = Executors.newFixedThreadPool(5);// Pool size fixed


executor.shutdown(); //  Will not take a new request ,


 does not wait for previously submitted tasks to

     * complete execution

executor.shutdownNow(); //  returns list of tasks that never commenced execution/ ignored and were in waiting state, attempt to stop the running thread;


Callable<T> callable= executor.submit(<Runnable >);
 Future<?> future = executor.submit(callable);
 Future<?> future = future.get(5, TimeUnit.SECONDS);//Timeout exception execution_time>5

No comments:

Post a Comment