【发布时间】:2013-10-25 17:18:34
【问题描述】:
我有一个带有 Producer 方法的 Singleton EJB。
@javax.ejb.Singleton
public class MyBean{
private Something something;
@Produces
public MySomething getSomething() {
if(null == something){
LOG.info("Initializing MySomething.");
something = new Something();
}
return something;
}
}
我以为这会锁定,但我在日志中多次看到此"Initializing MySomething.",然后某事抛出java.lang.StackOverflowError。
看来我需要锁定这个@Produces 方法。
可以为此目的使用java.util.concurrent.Semaphore 吗?
【问题讨论】: