aspose file tools*
The moose likes Threads and Synchronization and the fly likes Do newFixedThreadPool() of Executors,prevent the execution of last few number of threads from pool? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Do newFixedThreadPool() of Executors,prevent the execution of last few number of threads from pool?" Watch "Do newFixedThreadPool() of Executors,prevent the execution of last few number of threads from pool?" New topic
Author

Do newFixedThreadPool() of Executors,prevent the execution of last few number of threads from pool?

Mano Krrish
Greenhorn

Joined: Sep 10, 2010
Posts: 13
Hi All,
I am using newFixedThreadPool() from Executors class. when i am fixing the thread size to 2, last two threads are not completing their process,they just stay hanged...I get doubt in my usage of Executors. Could any one please verify the usage....Also say if i am using the shutdown() method properly....


Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

That all looks good to me. Nothing you show here should prevent the last 2 threads from executing. I suppose you are doing something else wrong. Perhaps indexing the siteArray wrong or causing an exception which isn't being handled correctly.

The below demo code shows the code you posted works properly to execute all the tasks. So the problem comes from someplace else... Things to check would include the siteArray being built the way you expect (has an even number of entries, and each place you expect an Integer value actually is an integer value), or code in the WebCrawlerBatch class prevents the worker threads from being released. There could actually be other exceptions that occur, so make sure you don't do something silly like catch(Exception e) { // do nothing }

>


Steve
Mano Krrish
Greenhorn

Joined: Sep 10, 2010
Posts: 13
Oh...Thanks Steve....I really made a silly mistake...I was not catching a "Null Pointer Exception" , which led to these things. Thanks for making me aware of this....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do newFixedThreadPool() of Executors,prevent the execution of last few number of threads from pool?