In general, using non-thread-safe classes across threads is fraught with many problems. In your particular case, assuming safe publication after all keys have had values assigned (such that map.size() == TheEnum.values().length
), the only problem I can see from a quickish glance of EnumMap
's code in Java 1.6 is that a put
may not ever get reflected in another thread. But that's only true because of the internals of EnumMap
's implementation, which could change in the future. In other words, future changes could break the use case in more dangerous, subtle ways.
It's possible to write correct code that still contains data races -- but it's tricky. Why not just wrap the instance in a Collections.synchronizedMap
?