Re: Using a lot of Maps
On 22-11-2010 18:13, markspace wrote:
On 11/22/2010 2:53 PM, Arne Vajh?j wrote:
Technically it is not immutable as hashCode changes its state.
Hmm, String is immutable and does the same thing.
Hmm.
So immutable then just means immutable in the documented
state.
That is flexible usage of English.
Safe, but not very elegant, because you have a test that
will make the calculation execute somewhere between one and
number of threads times.
I must disagree. The code is basically the same as String and in modern
systems, with their massive memory usages, is highly unlikely to execute
more than once. The lack of synchronization on that method is worth it
in the long run -- the more threads, the more worthwhile it becomes.
"Elegant" is in the eye of the beholder but I think you are picking at
nits here. The code is perfectly fine and imo elegant.
The fact that other code use the technique does not make it
elegant.
To some extent elegant is a matter of taste. But having
some code executed 1-N times depending on cache usage
pattern should not be considered elegant by anyone.
Given that String must by far be the class most used
with hashCode, then this type of code may be justified.
But that does still not make it elegant.
Arne
PS: Oh - and don't expect the "problem" to become
less probably on newer systems - the cache coherency
of x86/x86-64 is rather unique, RISC systems does not
have it, and Intel is talking about dropping it for
far out future systems
(http://www.itworld.com/hardware/128338/intel-1000-core-processor-possible).