| Author |
Doubt regarding ThreadPoolExecutor
|
Ravinder Rana
Greenhorn
Joined: Dec 07, 2006
Posts: 19
|
|
Hi all, Just want to know if ThreadPoolExecutor.execute() method ensures that if a idle thread is available in thread-pool or we have not reached the maximum thread limit yet, it will execute the submitted task immediately? Thanks
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
First, there are many different ExecutorService implementations, and there is no general guarantee that would apply to all of them. Since it's an interface, I could make my own implementation of it that may behave differently than those that Sun makes. Second, as soon as we're talking about threads, it's impossible to guarantee that anything will happen immediately. Even if the thread is started immediately, as long as there are other threads running, we can't guarantee how soon it will be before the new thread starts. Third, in all likelihood yes, the new Runnable will be assigned a pooled thread right away, and will start executing as quickly as any thread might be expected to execute. Which is generally pretty fast unless you have too many threads. I don't really see a way to answer this more specifically. You can always run some tests for yourself, logging times using System.currentTimeMillis() to see how much time elapses between calling execute() and calling run().
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: Doubt regarding ThreadPoolExecutor
|
|
|