It's not a secret anymore!
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

ThreadPoolExecutor question

Chris Gage

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.

Henry Wong

Joined: Sep 28, 2004
Posts: 20521

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).


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: ThreadPoolExecutor question
jQuery in Action, 3rd edition