I've the below @Singleton
EJBs:
@Singleton
public class RunBean {
private int id = new Random().nextInt();
public void printID() {
System.out.println("ID = " + id);
}
}
@Singleton
public class ParentBean {
@Inject
private RunBean runBean;
public void start() {
runBean.printID();
}
}
I'm @Inject
-ing them in the below web servlet:
public class Servlet extends HttpServlet {
@Inject
private RunBean runBean;
@Inject
private ParentBean parentBean;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
runBean.printID(); // out: ID = 69743
parentBean.start(); // out: ID = 193
}
}
I expected to see the same ID being printed. Why are they different?