*/
private Object findOrCreate(final ServiceDef2 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies)
{
final String key = def.getServiceId();
final Invokable create = new Invokable()
{
public Object invoke()
{
// In a race condition, two threads may try to create the same service simulatenously.
// The second will block until after the first creates the service.
Object result = services.get(key);
// Normally, result is null, unless some other thread slipped in and created the service
// proxy.
if (result == null)
{
result = create(def, eagerLoadProxies);
services.put(key, result);
}
return result;
}
};
Invokable find = new Invokable()
{
public Object invoke()
{
Object result = services.get(key);