HHH-8680 Relax synchronized block in TableGenerator#generate

This commit is contained in:
Sanne Grinovero 2013-11-13 14:10:37 +00:00 committed by Steve Ebersole
parent be44a1984e
commit 61a75accf5
3 changed files with 12 additions and 4 deletions

View File

@ -30,9 +30,14 @@ import org.hibernate.id.IntegralDataTypeHolder;
/**
* 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.
*/
public class NoopOptimizer extends AbstractOptimizer {
private IntegralDataTypeHolder lastSourceValue;
@Deprecated
public final class NoopOptimizer extends AbstractOptimizer {
private volatile IntegralDataTypeHolder lastSourceValue;
/**
* Constructs a NoopOptimizer
@ -45,7 +50,7 @@ public class NoopOptimizer extends AbstractOptimizer {
}
@Override
public Serializable generate(AccessCallback callback) {
public synchronized Serializable generate(AccessCallback callback) {
// IMPL NOTE : it is incredibly important that the method-local variable be used here to
// avoid concurrency issues.
IntegralDataTypeHolder value = null;

View File

@ -44,6 +44,9 @@ public interface Optimizer {
/**
* Generate an identifier value accounting for this specific optimization.
*
* All known implementors are synchronized. Consider carefully if a new
* implementation could drop this requirement.
*
* @param callback Callback to access the underlying value source.
* @return The generated identifier value.
*/

View File

@ -525,7 +525,7 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
}
@Override
public synchronized Serializable generate(final SessionImplementor session, Object obj) {
public Serializable generate(final SessionImplementor session, final Object obj) {
final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry()
.getService( JdbcServices.class )
.getSqlStatementLogger();