Discussions

General J2EE: Retaining objects across requests

  1. Retaining objects across requests (5 messages)

    Hi.

          I'd like to know how to retain objects across requests. I tried using singleton classes, but I think values stored in a singleton class are accessible to all users. I need to retain objects that are specific to a particular user, across different calls by that user.

          I am aware of how to use Stateful Session Beans to achieve this. This can also be done by serializing the object and persisting to the disc. But I am looking for a simpler solution. Any help in this regard is appreciated. Thanks in advance.

    -Parag Desai

    Threaded Messages (5)

  2. Retaining objects across requests[ Go to top ]

    Hi Parag,

    How about using the HTTP session object?

    Later,
    Rob Misek
    Tangosol, Inc.
    Coherence: It just works.
  3. Using init()[ Go to top ]

    Just create an object in your servlet class that you instantiate in the init() method. However, be sure to synchronize the "write" access to this object. If you modify this object very often, this is not a good solution as it will create a bottleneck.
  4. Retaining objects across requests[ Go to top ]

    Sorry for getting back so late... Yes, using the Session is the most obvious way, but the Session memory has been limited to ONLY 2Kb per user for my application (!!!). So I cannot use that approach. Some people mailed me saying I could write out the values to hidden fields on the JSP and get them through the HTTP Request in my Action class (Btw my application uses Apache Struts). I cannot do this either because what I want to save, is an Object, not just a String. Hope I'm not bugging too you too much.

    -Parag
  5. Retaining objects across requests[ Go to top ]

    Hi Parag,
    Yes, using the Session is the most obvious way, but the Session memory has been limited to ONLY 2Kb per user for my application (!!!). So I cannot use that approach.
    Are you running in a clustered environment? If so, you may want to check out Coherence*Web for your HTTP session management. Coherence*Web allow for linear scalable performance of HTTP sessions with no single point of failure or bottleneck. Also, there is on limit to the size of the session object.

    Later,
    Rob Misek
    Tangosol, Inc.
    Coherence: It just works.
  6. Retaining objects across requests[ Go to top ]

    Nopes, Rob. Not a clustered envmt. Standalone IBM WebSphere App Server, if that makes any difference. I'm currently doing away by serializing and writing the object into a temporary DB table. But I'd be glad to know anything better.

    -Parag