[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Does ScopeKey need to maintain a sorted (in ScopeLevel.l
adrian@jboss.org
do-not-reply at jboss.com
Tue Aug 11 09:39:32 EDT 2009
I don't understand why you have to change the ScopeKey?
I do understand that making it immutable with a builder is a better design, but
you're likely to break things if you change the semantics of the api.
THE PROBLEM:
If you go back to Jason's comments he talks about using a builder to create
a ScopeKey, but that's all a scope key really is.
The brain dead part is that it gets used at runtime in the BasicMetaDataRepository
as the key to a map which it then freezes to avoid mutablity.
The issue being that you still could incur contention because
of the synchronization on the scopes within the ScopeKey traversed in equals()/hashCode().
SOLUTIONS:
There are at least two ways you can fix this without changing the external api.
(The suggestions on improving the internal implementation should still be done)
1) Rather than having the synchronization and freeze() you could just
clone() the ScopeKey so that nobody can modify the ScopeKey once it is used by
the MDR (it is a different object), making the synchronizations irrelevant
but getting the same semantics.
2) The other is as I mention above. Use the ScopeKey as the builder class
and retrieve a more optimizated key for internal use within the MDR.
e.g. something like:
| public class ScopeKey
| {
| ...
|
| Object getOptimzedKey() {} // Key for use at runtime
| }
|
In fact (1) and (2) are just variations on the same theme, with (2) potentially
being more optimal.
POST SCRIPT
One further optimization would be to cache the hashCode()
since the key is used in ConcurrentHashMap. But I don't know that it is called
enough times (outside bootstrap/configuration) to make that worthwhile?
But, you're obviously seeing something to have looked at this in the first place?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249014#4249014
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249014
More information about the jboss-dev-forums
mailing list