Skip to content
Permalink
Browse files
Avoid duplicate processing with selective locking, improving performa…
…nce.
  • Loading branch information
ngmr committed Jun 21, 2016
1 parent 9caa74b commit 6c4cc03cd56214aa7e97ff61941dacac3a90bc9d
Showing 2 changed files with 12 additions and 6 deletions.
@@ -208,14 +208,17 @@ long getHashCode() {

@Override
protected void init() {
typeCode = genTypeCode();
getTypeCode();
}

private volatile TypeCode typeCode = null;
protected abstract TypeCode genTypeCode();
final TypeCode getTypeCode() {
// typeCode should have already been set from within init(), so this is just defensive
if (null == typeCode) typeCode = genTypeCode();
if (null == typeCode) {
synchronized (repo) {
if (null == typeCode) typeCode = genTypeCode();
}
}
return typeCode;
}
protected final void setTypeCode(TypeCode tc) {
@@ -831,9 +831,12 @@ protected ValueMember[] genValueMembers() {
return members;
}
final ValueMember[] getValueMembers() {
getTypeCode(); // ensure recursion through typecode for non-array types

if (null == valueMembers) valueMembers = genValueMembers();
getTypeCode(); // ensure recursion through typecode
if (null == valueMembers) {
synchronized (repo) {
if (null == valueMembers) valueMembers = genValueMembers();
}
}
return valueMembers;
}

0 comments on commit 6c4cc03

Please sign in to comment.