File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Statefull Bean - public member variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Statefull Bean - public member variable?" Watch "Statefull Bean - public member variable?" New topic

Statefull Bean - public member variable?

Swapan Mazumdar
Ranch Hand

Joined: Jul 23, 2003
Posts: 83
Hi Again,

Should a member variable be declared "public" to participate in session state in a Statefull Session Bean. I am simply startled to see a simple Count bean example from Ed Roman book which has a "public int val".
Is it part of the EJB Specs? What you people have to say about it? Guru are you listening? :roll:
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Swapan,

I don�t think so. I won�t make references to EJB specs, since I cannot remember the specs totally (I hope someone else will do), but when we speak about a SFSB�s session state I might consider couple of things:
  • The way SFSB�s state is saved/retrieved during passivation/activation.
  • The way the container saves the bean�s state in a cluster environment if a sever failure occurs.

  • As far as I remember the first one has nothing to do with public, private or protected variables. It has everything to do whether the attributes themselves are serializable or not.
    As for the second one, it is vendor specific. WebLogic for example does an in-memory replication of the SFSB, which means that it keeps two copies of the same bean on different server instance within a cluster, in a primary-secondary manner (they are kept in sync using IP-multicast). If the primary server fails, WL will redirect client�s requests to the secondary (which will get promoted to primary and another secondary will be picked up). Again this has nothing to do with whether the variables are public or not.
    Finally I would imagine that a strategy that doesn�t save "private" state would be error prone, since good OOD says that internal attributes must be declared private, no matter if the class is a POJO or a SFSB.

    I think, therefore I exist -- Rene Descartes
    Swapan Mazumdar
    Ranch Hand

    Joined: Jul 23, 2003
    Posts: 83

    Your explanation created special interest to my post. I personally found the points quite informative, especially, the second one. I now understand that access modifiers for instance variables should be declared private for SF Session Beans.

    I agree. Here's the link:
    subject: Statefull Bean - public member variable?
    It's not a secret anymore!