HHH-14444 Avoid synchronization for single-tenant generation in PooledLoThreadLocalOptimizer
Signed-off-by: Yoann Rodière <yoann@hibernate.org>
This commit is contained in:
parent
04a40f8397
commit
5c155f3f8d
|
@ -58,15 +58,18 @@ public class PooledLoThreadLocalOptimizer extends AbstractOptimizer {
|
||||||
public Serializable generate(AccessCallback callback) {
|
public Serializable generate(AccessCallback callback) {
|
||||||
if ( callback.getTenantIdentifier() == null ) {
|
if ( callback.getTenantIdentifier() == null ) {
|
||||||
final GenerationState local = localAssignedIds.get();
|
final GenerationState local = localAssignedIds.get();
|
||||||
if ( local.value != null && local.value.lt( local.upperLimitValue ) ) {
|
return generate( local, callback );
|
||||||
return local.value.makeValueThenIncrement();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final GenerationState generationState = locateGenerationState( callback.getTenantIdentifier() );
|
final GenerationState generationState = locateGenerationState( callback.getTenantIdentifier() );
|
||||||
|
|
||||||
if ( generationState.lastSourceValue == null
|
return generate(generationState, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Serializable generate(GenerationState generationState, AccessCallback callback) {
|
||||||
|
if ( generationState.value == null
|
||||||
|| !generationState.value.lt( generationState.upperLimitValue ) ) {
|
|| !generationState.value.lt( generationState.upperLimitValue ) ) {
|
||||||
generationState.lastSourceValue = callback.getNextValue();
|
generationState.lastSourceValue = callback.getNextValue();
|
||||||
generationState.upperLimitValue = generationState.lastSourceValue.copy().add( incrementSize );
|
generationState.upperLimitValue = generationState.lastSourceValue.copy().add( incrementSize );
|
||||||
|
@ -78,7 +81,6 @@ public class PooledLoThreadLocalOptimizer extends AbstractOptimizer {
|
||||||
}
|
}
|
||||||
return generationState.value.makeValueThenIncrement();
|
return generationState.value.makeValueThenIncrement();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, GenerationState> tenantSpecificState;
|
private Map<String, GenerationState> tenantSpecificState;
|
||||||
private final ThreadLocal<GenerationState> localAssignedIds = ThreadLocal.withInitial( GenerationState::new );
|
private final ThreadLocal<GenerationState> localAssignedIds = ThreadLocal.withInitial( GenerationState::new );
|
||||||
|
|
Loading…
Reference in New Issue