I'm trying to figure out if there is a 'groovier' way to iterate thread safe in Groovy than the usual way in Java iterating a Collections.synchronizedList inside a synchronized block, but I've found no reference to this issue (http://groovy.codehaus.org/Looping).
Are each and eachWithIndex thread-safe? If not, is there an easy way to iterate thread-safe already provided by Groovy? Or should I use the old Java way?
Thanks in advance.
Groovy's each uses iterators underneath (see the each method in DefaultGroovyMethods). As such, no, they would not be thread-safe in and of themselves. But you could obviously still use them within a synchronized block. You might also be interested in the @Synchronized AST transformation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With