Professional Documents
Culture Documents
Executorservice in Java
Executorservice in Java
Executorservice in Java
in Java
What is ExecutorService
• The Java ExecutorService interface, or TreadPoolExecutor
java.util.concurrent.ExecutorService , represents an
asynchronous execution mechanism which is capable of executing
tasks (Runnable Type Task) concurrently in the background.
• Goals:
1. user can set the size of the Thread Pool.
2. The ExecutorService creates and maintains a reusable pool of
threads for executing submitted tasks.
3. user can submit tasks to the ExecutorService.
4. It is the Responsibility of ExecutorService to execute
submitted task.
?How to create a ExecutorServisce
: Ideal Pool Size
1. Core Intensive :
it depends on the type of tasks you want to execute .
• IO intensive :
like -> HTTP Requast , URL or Request from Databse
: Summery
2. CashedThreadPool.
3. SynchronousThreadPool.
4. SingleThreadedPool.
:Pool Types (cont)
:Pool Types (cont)
:Pool Types (cont)
:Pool Types (cont)
:Pool Types (cont)
:Pool Types (cont)
:Pool Types (cont)
Benefits of Executor framework:
2. Max Pool size -> maximum number of threads the pool can
take , it depends on the pool type -> int .
3. keepAliveTime-> the time the thread stays alive -> long.
FixedThreadPool
LinkedBlockingQueue
SingleThreaded
DelayedWorkQueue ScedualedThreadPool
: Rejection Handler
1. Abort Policy : submitting new task throws
RejectedExcutionException (Runtime Exception).