Difference between @Stateless and @Singleton

You’re seeing the same output because there is only one client accessing the EJB at a time. The application server is able to recycle the same stateless EJB object for each call. If you try a concurrent access – multiple clients at the same time – you’ll see new stateless instances appearing.

Note that, depending on the server load, even two consecutive method invocations made by the same client may end up in different stateless EJB objects!

For a singleton EJB, there will no difference – there is always only one instance per application, no matter how many clients try to access it.

Leave a Comment

tech