I am trying to understand what could be done with @Stateful beans, given @SessionScoped CDI beans. I created this JAX-RS resource:
@Path("ping")
public class PingResource {
@Inject
private StatelessCounter statelessCounter;
@Inject
private StatefulCounter statefulCounter;
@Inject
private SingletonCounter singletonCounter;
private long jaxrsCounter;
@GET
@Path("/counter")
public String incrementAndGetCounter() {
statelessCounter.incrementCounter();
statefulCounter.incrementCounter();
singletonCounter.incrementCounter();
jaxrsCounter++;
return statelessCounter.getCounter() + " " + statefulCounter.getCounter() + " " + singletonCounter.getCounter() + " " + jaxrsCounter;
}
}
Just to understand behavior of stateful bean. But, everytime I call /counter
endpoint, I always get a fresh statefulCounter
. I just want to know what is the criteria for the EJB container to return same stateful object used before; as it is stateful, there must be a way to get the same old object.