_concurrentSemaphore = null;
}
public Item<X> allocate()
{
Semaphore semaphore = _concurrentSemaphore;
if (semaphore != null) {
try {
Thread.interrupted();
if (! semaphore.tryAcquire(_concurrentTimeout, TimeUnit.MILLISECONDS))
throw new RuntimeException(L.l("{0} concurrent max exceeded", this));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
boolean isValid = false;
try {
Item<X> beanItem = _freeList.allocate();
if (beanItem == null) {
CreationalContextImpl<X> env = new OwnerCreationalContext<X>(_manager.getBean());
Object []bindings;
X instance = _context.newInstance(env);
bindings = _manager.getInterceptorBindings(_interceptorBeans, env);
if (instance instanceof SessionBean) {
try {
((SessionBean) instance).setSessionContext(_context);
} catch (Exception e) {
log.log(Level.WARNING, e.toString(), e);
}
}
beanItem = new Item<X>(instance, bindings);
Item<X> oldInstance = _lifecycleInstanceLocal.get();
try {
_lifecycleInstanceLocal.set(beanItem);
_proxy.__caucho_postConstruct();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
_lifecycleInstanceLocal.set(oldInstance);
}
// _ejbProducer.newInstance();
}
isValid = true;
_manager.setLocalStatelessPool(this);
return beanItem;
} finally {
if (! isValid && semaphore != null)
semaphore.release();
}
}