diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java index 867e36d9d9..99f936db0a 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/OptimizerFactory.java @@ -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();