File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Confused about STFL and STLS beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Confused about STFL and STLS beans" Watch "Confused about STFL and STLS beans" New topic

Confused about STFL and STLS beans

Kiril Nugmanov
Ranch Hand

Joined: Jul 09, 2008
Posts: 42
Hi all,

I'm really confused about usage of STFL and STLS beans .
The main difference benwen them is that STFL can hold clients state and STLS can't. Thus I tried to test it with local client.
(1) Created 2 EJBs - StatelessBean and StatefullBean
(2) Deployed to Glassfish 2.1.1 AS. No any aditional configurations were made.

First time I called client and set "data" variable to 1 in STFL and STLS beans. By second call I just tried to obtain that value.
Results in fist time were as supposed:

But when calling second time I obtained following results:

There is no question about STFL - each time I obtain reference to new STFL bean thus value is 0. But why I obtained the same STLS bean
There is server.log

Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
This is exactly how stateless bean behaves, the server uses the same instance of the stateless bean to serve multiple clients requests.
That is why it is not recommended for you to keep state in the stateless bean as your instance may end up serving a totally different client.
To recap what I have just said, any instance of stateless bean in the pool can serve any client. However statefull session bean instance are attached to the client that created it and can't be reused by another client while it is in use.
Kiril Nugmanov
Ranch Hand

Joined: Jul 09, 2008
Posts: 42
Hi Hany Shafik,

Thanks for clearing the situation.
I agree. Here's the link:
subject: Confused about STFL and STLS beans
It's not a secret anymore!