Mageshkumar Maruthapillai wrote:

> Hi,
>
> I have an a sample form which posts to a servlet say. Well, due to
>
> slow internet connections etc.. the servlet response takes some time to
>
> reach the browser. An impatient user can press the submit button many times.
>
> Say 20. Does this mean that for from this particular user there will be 20
> concurrent
>
> threads excecuting concurrently in the servlet instance.

Presuming that the first request hasn't finished yet by the time you hit the
submit button the 20th time, this is certainly possible.

>
>
> Will this cause a synchronisation problem w.r.t. individual user session
> data.??
>

Depends totally on your session data.  For read-only things this should not be a
problem.  For read-write things, it is up to the design of the beans you store
in the session to protect yourself from problems.

One thing you could do to minimize problems is store an "I am working on this"
object in the user session.  The first request in will store this object and
start responding to the request.  The 2nd through 20th requests would seee that
this object is already there, and return an error page instead of initiating 19
more database lookups.

>
> I think it should. Does the Servlet container serialize multiple requests
> for the
>
> same servlet instance from the same client browser????
>

Not in the general case.

You can implement the SingleThreadModel interface in your servlet, and the
container will serialize accesses to a particular servlet instance (for all
users, not just one), but that does NOT solve your problem.  It's also legal for
the servlet container to have multiple instances of a SingleThreadModel servlet
running, so you could still be hitting your session data multiple times for the
same user.

>
> Any answers towards this rather overlooked problem is appreciated.
>

It's not an issue of an "overlooked" problem -- it's an issue of application
design.  To write a robust web application, you must be aware of the fact that
your application objects can be accessed in a multithreaded environment (not
just for a single user; for example, servlet instances are shared across ALL
users).  These issues are not unique to servlets; all the general principles of
multithread applications architecture and thread safe programming apply.

>
> Thanks,
>
> Magesh.
>

Craig McClanahan

___________________________________________________________________________
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