@dieu, I agree with you: the close() method should better be thread-safe, and
as Andrew pointed out, the state variable should also be private, to avoid
unexpected internal state changes.
Using an AtomicReference or not, the important thing is to make sure that stuff
is closed only once by only one thread. That means the loop should be protected
so only the first thread enters it. The close method should be thread-safe, and
something like:
if OPEN:
change to CLOSING
close stuff
change to CLOSED
Only the first thread should enter the condition and close stuff, and the other
ones should just do nothing. That's why I asked about synchronizing the method
(as it does nothing else). Atomically modifying the state variable might not be
enough to protect the loop.
---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/32#issuecomment-19481858