Using Handle when Session bean is Stateless

Discussions

EJB programming & troubleshooting: Using Handle when Session bean is Stateless

  1. Using Handle when Session bean is Stateless (5 messages)

    Does someone know what happens if you try to do the following call in client in order to get the Staless Session bean, and the bean you have the handle is already removed by the garbage-collector?

    Handle h = ...// get the old handle from memory or deserialize it from disk (or wherever you have it
    h.getEJBObject();

    Should the server give you some random sessionbean from cache or does it return null? The server we are using is WebLogic 6.1.
  2. I don't know the answer, but my guess is that an instance from the pool will be returned.

    Why would you want a handle to a stateless bean?

    Maybe you should try an experiment and post your results.
  3. Hi,

    Generally handles are used to save the state to the storage and retain it back when the client connects later.

    Since the state is serialized ( in the case of stateful session bean) you'll be able to reconstruct it using the handle.It has nothing to do with garbage collection because when you deserialize it you are creating a new instance out of the serialized state.

    Stateless session beans do not hold state and there is no use obtaining the handle.

    Thanks
    Karthik
  4. The use of an Handle is NOT in any way about saving state. It is about storing a "reference" to an EJB. The handle just allows you to "refer" to an EJB (Entity or Session).

    A Handle is a special kind of "reference" that can be serialized.

    Because it can be serialized you can store it to disk, transmit it to another program, etc.

    But all you have in the end is a reference to an EJB.
  5. By saving state what I meant was saving the reference to the current EJB Object which holds the conversational state with the bean instance. It is quite understood that we do not have direct control over bean instances and their state, because it is controlled by the container.

    Why would you want to use a handle if not for retaining the conversational state. I do not understand the point of handles in the case of Stateless session beans and entity beans.In the case of stateless session bean, we can always create a new ejb object and in the case of entity beans since the bean instances can always be "found" we can use finder methods to associate an Ejb object with bean instance whenever we need it.


  6. The reason for me to have a Handle for a Stateless Session Bean is that in the requirements of the system we are implementing is that this specific component has to be "pluggable". So the client should not know anything about the session bean. In our case statefullness/statelessness only adds some efficiency concerns from different viewpoints. The use of Handle enables us to use the benefits of stateful bean, and if it works how I assume it should for stateless bean, it enables the "pluggable"-feature for the client...