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

Can i process iterator in parallel?

rudra tripathy
Greenhorn

Joined: May 26, 2004
Posts: 25
Hi All,

I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

rudra tripathy wrote:
I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?


If you are asking if iterators are thread safe, that would depend on where you got the iterator from.... In most cases, however, iterators are not thread safe, so you will need to wrap it with a lock.

If you are asking if iterators are thread safe, and can distribute (divide up) the element into specific batches. The only way to do that is to have a thread specifically for dispatch -- it is not possible (read very difficult) to dispatch evenly if the workers threads are responsible for fetching the elements. Have a thread do it, and move it to the individual data structures for the threads.

So, the answer is yes... but not without some help from you.
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

rudra tripathy wrote:Hi All,

I have one iterator of size, say 100. I want to divide it 10 batch of 10 and process it. Is it possible?


The Iterator doesn't have a size. The thing it's iterating over does. You can certainly divide the processing up, yes. I probably wouldn't do it with multiple threads accessing the iterator though, or, if I did, I'd be careful about synchronization.
rudra tripathy
Greenhorn

Joined: May 26, 2004
Posts: 25
Hi Henry/Jeff,

Thanks for the clarification.

Thanks and Regards,
Rudra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i process iterator in parallel?
 
Similar Threads
Page wise display
how come i can't call my search method from my main method?
Collection 3
Which design pattern JDBC-Resulset implements : Bridge, iterator, composite, factory
using Iterator or without using Iterator