aspose file tools*
The moose likes Threads and Synchronization and the fly likes Blocking I/O using Iterator() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Blocking I/O using Iterator()" Watch "Blocking I/O using Iterator()" New topic
Author

Blocking I/O using Iterator()

Matt Elliott
Greenhorn

Joined: Feb 21, 2009
Posts: 14
In profiling my java application I noticed that the iterator() method was blocking on the arraylist data structure.
Is it better to use the get() method to remove the block or stick with the iterator?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
That's a very strange symptom you describe. What does it have to do with I/O? Do you mean blocking in the sense that threads block when they try to enter a synchronized block or method, and can't, because they can't acquire the lock? Probably not, but that's what block usually means. Or do you just mean that your program spends too much time executing this method? That's surprising to me. Are you sure the problem is really with the iterator() method, and not in other methods called on the Iterator, like hasNext() or next()?
Matt Elliott
Greenhorn

Joined: Feb 21, 2009
Posts: 14
Mike, you're right.
I was just miss interpreting the profiler's results, but in re-examining it, it lead my to the question:
Is the new keyword synchronized, in the sense that multiple threads can't instantiate data structures simultaneously?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
No, new is not synchronized.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blocking I/O using Iterator()