This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Doubt regarding ThreadPoolExecutor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Doubt regarding ThreadPoolExecutor" Watch "Doubt regarding ThreadPoolExecutor" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt regarding ThreadPoolExecutor
 
Similar Threads
Thread & Synchronization
Thread and Object
Tech Word Game
subject
WA #1.....word association