Comparison of various ThreadPoolExecutor service in java.util.current package.
| Parameters | Description | CachedThreadPool | FixedThreadPool | ScheduledThreadPool | SingleThreadExecutor | SingleThread ScheduledExecutor |
| CorePoolSize | No. of threads to be in pool even if they are idle. | 0 mean no limit | User given value | User Given value | 1 | 1 |
| MaximumPoolSize | the maximum number of threads to allow in the pool | Integer.MAX_VALUE | Same value as CorePoolSize | Integer.MAX_VALUE | 1 | Integer.MAX_VALUE |
| KeepAliveTime | When the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating. | 60 | 0 | 0 | 0 | 0 |
| Unit | the time unit for the keepAliveTime argument | SECONDS | MILLISECONDS | NANOSECONDS | MILLISECONDS | NANOSECONDS |
| WorkQueue | The queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method. | SynchronousQueue < Runnable> | LinkedBlockingQueue <Runnable> | DelayedWorkQueue | LinkedBlockingQueue <Runnable> | DelayedWorkQueue |
In short SingleThreadExecutor is FixedThreadPoolExecutor with core pool size and max pool size as ‘1’.
SingleThreadScheduledExecutor is ScheduledExecutor with core poolsize as ‘1’.
Apart from above predefined executor services. Concurrent package gives flexibility to customize the parameters of the ThreadPool by using ThreadPoolExecutor class.
Example:
ExecutorService ex = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
No comments:
Post a Comment