aspose file tools*
The moose likes Threads and Synchronization and the fly likes ThreadPoolExecutor question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "ThreadPoolExecutor question" Watch "ThreadPoolExecutor question" New topic
Author

ThreadPoolExecutor question

Chris Gage
Greenhorn

Joined: Mar 23, 2005
Posts: 17

Although I have been doing Java as long as it has been around, I have never done any multi-threaded code, so here is a question that has been worrying me...

I am using a ThreadPoolExecutor to read HTML pages from an ancient web site created about 12 years ago, and reformat them from HTML3 to XML/XSLT. Each page read from the site is queued for reformatting, but also has links to other pages. As a consequence, the thread itself needs to add new pages to the queue. Is there anything dangerous about the thread queuing new requests? My greenness with java.util.concurrent makes me cautious.

truebrit
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18717
    
  40


There is nothing unsafe with queuing new requests in a threaded manner. The queue is threadsafe.

The only danger is if the new requests interact with the old request -- the executor doesn't protect the tasks from each other (but that is true, and must be dealt with, with any task).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ThreadPoolExecutor question