I've always regarded Java's volatile
variables as voodoo
variables. In fact, I've been scared off by very many articles telling you how terribly dangerous they are. In cases like these I tend to retreat to the safety of a few good patterns.
Except, I could never find any good patterns for using volatile
. Luckily, Brian Goetz has just written an article solving this problem! Go check out Managing volatility.
The patterns are:
- status flags
- one-time safe publication
- independent observations
- the “volatile bean” pattern
- the cheap read-write lock trick
And hey, it's Brian Mr. Concurrency Goetz, so this stuff has to be good!
tag gen:Technorati Tags: brian goetz java concurrency thread safe volatile variable Del.icio.us Tags: brian goetz java concurrency thread safe volatile variable