HHH-9268 The NoopOptimizer used for default id generation doesn't need synchronization

This commit is contained in:
Sanne Grinovero 2014-07-01 21:49:37 +02:00
parent a7822712cc
commit 92bd9e6310
1 changed files with 9 additions and 8 deletions

View File

@ -236,22 +236,23 @@ public class OptimizerFactory {
* An optimizer that performs no optimization. The database is hit for
* every request.
*
* @deprecated This is the fallback Optimizer chosen when we fail to instantiate one
* of the proper implementations. Using this implementation is probably a performance
* problem.
* Using this implementation is probably not the most efficient choice.
*/
@Deprecated
public static final class NoopOptimizer extends OptimizerSupport {
private volatile IntegralDataTypeHolder lastSourceValue;
private IntegralDataTypeHolder lastSourceValue;
public NoopOptimizer(Class returnClass, int incrementSize) {
super( returnClass, incrementSize );
}
@Override
public synchronized Serializable generate(AccessCallback callback) {
// IMPL NOTE : it is incredibly important that the method-local variable be used here to
// avoid concurrency issues.
public Serializable generate(AccessCallback callback) {
// IMPL NOTE : this method is called concurrently and is
// not synchronized. It is very important to work on the
// local variable: the field lastSourceValue is not
// reliable as it might be mutated by multipled threads.
// The lastSourceValue field is only accessed by tests,
// so this is not a concern.
IntegralDataTypeHolder value = null;
while ( value == null || value.lt( 1 ) ) {
value = callback.getNextValue();