On Wed, 2002-01-09 at 15:11, marc fleury wrote:
> So I just spent 2 hours spotting the following interesting bug
>
> HashMap deployments ...
>
> Iterator it = deployments.keySet().iterator();
>
> while (it.hasNext());
> {
> do something();
> }
>
> which would peg my CPU at 100% and never reach do something ...
>
> man I am a clown... can you see it? 2 hours!
It happens to everyone (many times, even) :-)
FWIW: Effective Java by Joshua Bloch proposed a different standard
method for accessing iterators. To use your example:
for ( Iterator it = deployments.keySet().iterator(); it.hasNext; )
{
Object blah = it.next();
...
}
In his view it eliminates errors where you use common variables (e.g,
'it' for an iterator) multiple times in the same scope. Makes sense to
me.
Excellent book, BTW
Chris
--
Chris Winters ([EMAIL PROTECTED])
Java Developer
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development