Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Blocking I/O using Iterator()

 
Matt Elliott
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, new is not synchronized.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic