Skip to content

Commit

Permalink
HHH-9268 The NoopOptimizer used for default id generation doesn't nee…
Browse files Browse the repository at this point in the history
…d synchronization
  • Loading branch information
Sanne committed Jul 1, 2014
1 parent 75aac4f commit 98771c2
Showing 1 changed file with 9 additions and 8 deletions.
Expand Up @@ -31,13 +31,10 @@
* 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 final class NoopOptimizer extends AbstractOptimizer {
private volatile IntegralDataTypeHolder lastSourceValue;
private IntegralDataTypeHolder lastSourceValue;

/**
* Constructs a NoopOptimizer
Expand All @@ -50,9 +47,13 @@ public NoopOptimizer(Class returnClass, int 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();
Expand Down

0 comments on commit 98771c2

Please sign in to comment.