Question

OS: Windows 7 JVM: JavaSE 1.7 Java EE: JBoss AS 7.1.1

scenario:

@Path("/test")
@RequestScoped
public class TestService {

    @Inject
    private Instance<Dummy> dummyinInstance;


    @Path("/execute")
    @GET
    public void execute() {
        dummyinInstance.get().execute();
    }

}

@Stateless
public class Dummy {
    private Date date=new Date();

    public void execute() {
        System.out.println("current date="+date);
    }
}

When i execute remotely ( with a rest client) Teservice:execute many time, the same date is printed.

Was it helpful?

Solution

A Stateless Session Bean means not, that a Session Bean has no intern state. Variables don't become empty after a call. And a SLSB will not be destroyed so fast(well, you can configure it). Intern variables hold their values.

But a client to a Stateless Proxy has no warranty that he gets the same SLSB after several calls. In fact it can sometimes look like you interact with a SFSB because the container invokes methods on the same SLSB from his pool of SLSB but you should never rely on it.

If you try it with several clients the same time, I'm sure that you see the behaviour you expected.

Edit: The sequencey of calls looks a little bit like this(simplefied)


TestService->SLSB-Proxy->Container-Magic->Pool->Even more Container-Magic->Dummy


And your first instance is called again and again because there is no need to create another instance before the is more payload.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top