Discussions

EJB design: Removing Stateful Session Beans

  1. Removing Stateful Session Beans (1 messages)

    Hi,

    well this is a tricky question I have :
    1) a Customer calls a CustomerAgent which resides within the EJB Server. CustomerAgent is a stateful session bean.
    2) CustomerAgent then posts several messages to different topics.
    3) CustomerAgent polls the topics for answers meeting different criterias. This polling is done within a loop. The time this Agent is within the loop can vary from 1 second to 2 days.

    My question :
    can CustomerAgent be passivated or even removed by the container while polling, especially if the bean is performing a loop inside a method, which can last for several days ? The Customer having called the method times out, but CustomerAgent is still performing the loop - will it be removed ?

    For your information : I dont want the Agent to be removed or passivated.

    Thanks in advance,

    Jubin Zawar
  2. The statefull session bean cannot be passivated or removed during methods execution. Passivation occurs between method calls.

    Bean instance may be removed when:
    - remove() is called by client
    - instance throws an exception
    - timeout occurs (responsibility of the container, most containers removes the least frequently used beans).

    I don't know if using statefull session bean is the correct solution for your problem. If you have some event-triggered scenarios (publish and subscribe model) you should probably use JMS or (if available) Message Driven Beans (EJB 2.0).

    Regards

    Wojtek