

|
|
Home >> Java
Explaining ThreadPoolExecutor from java.util.concurrent package
newly introduced in 1.5 version of JDK.
As of JDK 1.5, ThreadPoolExecutor has Four constructors such as
ThreadPoolExecutor with five arguments in constructor, such as
1. Core Pool Size with int data type.
Number of sub threads available at any given point of time
including all idle threads.
2. Maximum Pool Size with data type as int.
maximum number of threads allowed in this pool executor
3. Keep thread alive time with data type as long.
Any thread that has count more than the core pool size of this
thread pool, and is idle/completed execution of any task,
to be kept alive for this (keep alive time) period, before
terminating/not alive state.
4. Time unit as data type TimeUnit from java.util.concurrent package
Time format to be used for keep alive time value, such as
Micro seconds, milli seconds, nano seconds, seconds.
5. queue of all threads put in it and is having data type as BlockingQueue
from java.util.concurrent package.
This queue can hold all the runnable objects those will be executed
along with any of the thread present inside the pool of threads in this thread
pool executor.
|
|  |
|
Question: Is it neccessary to have all the task provided to thread pool executor be
implementing Runnable?
Answer: No, Task can be implmenting Runnable or Callable (interface from
java.util.concurrent package).
Question: What are the differences between Task implementing Runnable and Task
implementing Callable interface?
Answer: As we know that Runnable interface has a method run with no argument
and that doesnot throw any checked exception, but Callable interface has a method
call that throws Exception (any checked exception) and has a return type as Object
(so any Object type can be returning with appropriate type casting).
This means by using Callable call method, one can have some return comming out of
Task to the caller program, can be used to return any desired status or return value
and the throwing of checked exception makes it easier for the Task to throw application
specific checked exception back to the caller program, in case there is any exceptional
condition arises.
Question: Do you mean to say that there will be difficulty in handing checked exception
in case of using Runnable Task with ThreadPoolExecutor?
Answer: No, there is a callback handler in ThreadPoolExecutor that notifies any
checked or unchecked or runtime exception happening during execution , but this happens
only after the Task execution completes/abruptly temninates because of any exception,
and on afterExecute callback method by passing the Task and any exception
along with it to the caller program.
If you like to share your comment/suggestions/feedback relating to this Page,
you can do so by droping us an email at usingframeworks @ gmail . com
with the subject line mentioning URL for this Page (i.e, /Java-threadpoolexecutor.php) or use this
LINK.
As per this website's privacy policy, we never disclose your email id,
though we shall post your comments/suggestions/feedback with
your name (optional) and date on this Page. If you don't want your
comments/suggestions/feedback to be shared in this Page, please
mention so in your email to us. Thank you very much.....
If anything missed out , please let me know at
techienjoy at yahoo . com
References :
Tags: java comparator reflection
Tags: java example drag n drop
Tags: Java Interview Questions
Tags: java rmi tutorial stub skeleton
Tags: Java Thread Deadlock
Tags: Java Thread Design Scenarios
Tags: Java threadpoolexecutor
Tags: Java
DISCLAIMER :
The content provided in this page is not warranted and/or guaranteed by techienjoy.com.
techienjoy.com is not liable for any negative consequences that may result/arise from
implementing directly/indirectly any information covered in these pages/articles/tutorials.
All contents of this site is/are written and provided on an "AS IS" basis,
without WARRANTIES or conditions of any kind, either express or implied, including, without
limitation, merchantability, or fitness for a particular purpose. You are solely responsible
for determining the appropriateness of using or refering this and assume any risks associated
with this.
In spite of all precautions taken to avoid any typo in these pages, there might be some
issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
extends sincerest apologies to all our visitors for the same.
|
| 

|