Java Reference
In-Depth Information
LISTING 4‐9: Specifying startup order using @depends annotation
package com.devchronicles.singleton;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.DependsOn;
import javax.ejb.EJB;
@Startup
@DependsOn("MyLoggingBean")
@Singleton
public class CacheSingletonBean {
private Map<Integer, String> myCache;
@EJB
MyLoggingBean loggingBean;
@PostConstruct
public void start(){
loggingBean.logInfo("Started!");
myCache = new HashMap<Integer, String>();
}
public void addUser(Integer id, String name){
myCache.put(id, name);
}
public String getName(Integer id){
return myCache.get(id);
}
}
Next let's create another singleton bean (Listing 4‐10), which the previous bean already referenced.
LISTING 4‐10: Specifying startup order
package com.devchronicles.singleton;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import java.util.logging.Logger;
@Startup
@Singleton
continues
Search WWH ::




Custom Search