Cabbar Duzayak wrote:

> Hi;
>
> I need to develop a website using JServ. As far as I know, there are
> two alternatives to share data between users' different requests (e.g.
> shopping cart, authentication, etc.) ;
>
> One of the alternatives is to use HTTPSession object and transfer
> related data automatically, this seems pretty easy to implement, but
> as far as I know all the information is kept in memory (or swapped,
> whatever) and things like hash tables are used to improve performance.
>

Yes, the objects you store in your session are resident in memory.  In
fact, the putValue() and getValue() methods of HttpSession do indeed use a
hash table to store the values and retrieve them quickly.

Some servlet engines provide support for swapping sessions to disk or some
other persistent store.  This is not currently supported in Apache JServ,
but there is work in progress to support this in a future version.

>
> The other option is to give each user an ID like session ID,
> store this session ID in a cookie and store the related information in
> a database along with this session ID. In my case, I am using Oracle
> 8.
>
> If you have a heavy traffic on your web site, as you can see, there is
> a trade of here between eating up server memory (in case of using
> HTTPSession) and time for sending inserts, deletes and queries to
> database.
>
> I am not actually sure about which one to use and I appreciate your
> comments about this issue.
>
> Thanks ...
>

I don't see that these two approaches are mutually exclusive.  For
example, you can store "little" things in the session, and then use the
session ID (which is a string) to construct keys that access "big" things
from the database, without having to deal with your own cookies.  The
session support in the servlet API also has a nice feature that lets your
data objects receive a notification when they are removed from the session
(either deliberately, or because the session was invalidated) -- you could
use the reception of this event to clean up any temporary data you've got
in the database, for example.

Repeatedly accessing information from the database on each request will
definitely take time -- whether or not it is too much depends entirely on
your application.  If you have enough memory available, the database
itself will cache these things in memory, but if that is the case you
could just as easily leave them in session variables and allocate that
memory to the servlet engine instead.

Craig McClanahan




----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to