I'm doing a shopping cart, and I've stumbled upon the problem of concurrency
with regard to the array that I keep the results of a users database query in.
Currently, the servlet gets an array of products from the DB, and refers back
to it later on in order to print out an HTML table with all the goodies in.

Which raises the question:  How visible are the variables in a servlet?
Can everybody potentially write over the variables of everybod else?
If two customers are both shopping at the same time, sharing the products
array, then products = db.getProducts("sand blasters") will write over
whatever product array the other user had done a search for. I'm trying to
overcome this by binding the product array to the session so I can do this:

Product[] products=(Product)session.getValue("products");
    for (blah blah blah){
        out.println("<fancy table HTML>product[i]</fancy table HTML>");
    }
What happens though if in between
 products = session.getValue("products");
and the next bit, somebody stomps in with a
products=db.getProducts("Scouse beer mats"),
?

Do we need to go as far as synchronising (haven't done any of this yet) the
retreival of the products array from the clients session, putting the results
of a database search in it , and putting it back in the session? What I mean
by "synchronising" is: locking access to the variable until I've carried out
all the necessary on it so that nobody else can corrupt the data. Is that
what "synchronising" means, or am I thinking of something else?

Can anybody help?

Cheers
Peet

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to