4 ms·
In my career, I have used volatile incorrectly many more times than I have used it correctly. :) For readers who are not deeply familiar with Java's volatile k
by throwaway2037 5y ago
In my career, I have used volatile incorrectly many more times than I have used it correctly. :) For readers who are not deeply familiar with Java's volatile keyword, you can read more about it here: https://stackoverflow.com/questions/13688697/is-a-write-to-a-volatile-a-memory-barrier-in-java https://stackoverflow.com/questions/13688697/is-a-write-to-a...
I feel the same about robust, easy to maintain enterprise software: Just use a blocking queue (or disrupter circular buffer for speed freaks) and make all messages/requests immutable. It is a trivial concept to explain to new hires and all but guarantees "boring" thread-safe code can be written by junior devs.
I think I finally understood volatile (in a pratical setting) when I read the source code for class CopyOnWriteArrayList. To be honest, the first few times I read it... the pattern made no sense. I thought to myself: "Why use volatile?" After reading many times (and using volatile wrong many times), I finally understood the pattern.