| 1. |
What Is Executors In Java Executor Framework? |
|
Answer» Executors is a factory that PROVIDES the methods to return ExecutorService, ScheduledExecutorService, ThreadFactory. Find some method details. newFixedThreadPool(): It RETURNS the pool with fixed number of size. We need to pass the number of threads to this method. If concurrently task are submitted more than the pool size, then rest of task need to wait in QUEUE. It returns ExecutorService. newScheduledThreadPool: This also creates a fixed size pool but it can schedule the thread to run after some defined delay. It is useful to schedule the task. It returns ScheduledExecutorService. newCachedThreadPool(): There is no fixed size of this pool. Thread will be created at run time and if there is no task it will ALIVE for 60 second and then die. For short lived threads this pool WORKS good. It returns ExecutorService. Executors is a factory that provides the methods to return ExecutorService, ScheduledExecutorService, ThreadFactory. Find some method details. newFixedThreadPool(): It returns the pool with fixed number of size. We need to pass the number of threads to this method. If concurrently task are submitted more than the pool size, then rest of task need to wait in queue. It returns ExecutorService. newScheduledThreadPool: This also creates a fixed size pool but it can schedule the thread to run after some defined delay. It is useful to schedule the task. It returns ScheduledExecutorService. newCachedThreadPool(): There is no fixed size of this pool. Thread will be created at run time and if there is no task it will alive for 60 second and then die. For short lived threads this pool works good. It returns ExecutorService. |
|