When should member/instance variables be cleared in beans?

Discussions

EJB design: When should member/instance variables be cleared in beans?


  1. Is it true that if member variables are not cleared down in a session bean and the bean is destroyed, when another client picks up the bean, then the values are still in the instance vars.

    Therefore should these variables always be cleared down in the remove event? Also is this the best event to do this?
    As far as I know, create isn't called every time, so it would be no good in here, or is it called everytime?

    Cheers.


  2. Nick,
    I assume you are talking about Stateful Session beans here. You can clear the attributes either in ejbActivate() or ejbPassivate(), can't you? Or am I missing something?
    --Das
  3. I was sort of talking about both. Let me rephrase it.
    When a stateless session bean is removed. Are the instance fields cleared automatically? I don't think so.

    Secondly, the same question for stateful session bean. Here, I think they are. Are they? We don't want to clear the fields in activate and passivate, otherwise we lose our information.

    I just need to know if I'm right on these.

    Cheers.
  4. Hi Nick,

    if session beans are removed, regardless whether it is stateless or stateful, the state of the instance fields is lost, because the instance of the bean is removed.

    Regards
    Michael