Skip to content

Commit

Permalink
Micro-tuning for StandardListenerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Aug 2, 2013
1 parent 8aff7db commit aea6b76
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -24,7 +24,6 @@
package org.hibernate.jpa.event.internal.jpa;

import javax.persistence.PersistenceException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.hibernate.jpa.event.spi.jpa.ListenerFactory;
Expand All @@ -36,7 +35,8 @@
* @author Steve Ebersole
*/
public class StandardListenerFactory implements ListenerFactory {
private Map listenerInstances = new ConcurrentHashMap();

private final ConcurrentHashMap listenerInstances = new ConcurrentHashMap();

@Override
@SuppressWarnings("unchecked")
Expand All @@ -52,7 +52,10 @@ public <T> T buildListener(Class<T> listenerClass) {
e
);
}
listenerInstances.put( listenerClass, listenerInstance );
Object existing = listenerInstances.putIfAbsent( listenerClass, listenerInstance );
if ( existing != null ) {
listenerInstance = existing;
}
}
return (T) listenerInstance;
}
Expand Down

0 comments on commit aea6b76

Please sign in to comment.