posted 17 years ago
There are no simple rules for multi-threaded programming. You have to think through each case.
If you are new to multi-threading, I would recommend forgetting about "volatile" entirely. You never need volatile; it is just a way of gaining more concise code and/or small performance gain. Get used to using "synchronized" correctly and effectively.
By the way, ConcurrentHashMap is right at the other end of the code sophistication scale to Vector. ConcurrentHashMap has been carefully optimised to the Nth degree by very smart people. Some of the reasons for particular synchronisations, or the lack of them, are probably very subtle. It might be difficult to extract learning points for ordinary, non-performance-critical, code from ConcurrentHashMap.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.