Synchronziation is good, but has one major problem.  The problem with
synchronization is that if the user clicks the click 5 or 6 times, you
can potentially have 5 threads all waiting to aquire the lock.  Since
all users are sharing a thread pool, this can lead to thread-pool
starvation performance problems.  If all the threads in the thread-pool
are busy, then even the most simplest of pages won't load, and the site
will appear to be down.

What you really want here is to use a "Load Control Filter".  Here's how it
works...

Policy:

(a) Prevent more than 1 thread from entering the same HttpSession at a time

(b) If another thread is already waiting, threads queue up, up to a max
    queue length.

(c) If the max queue length (2) is exceeding, we want to give preference to
    the most recent clicks, failing the oldest clicks.  So we remove the
    oldest waiting thread in the queue and fail it with a user error, and
    add the most recent click to the queue.

This can be done by creating a special Lock object that manages this policy
and storing the lock object in the HttpSession.  Then, you use a
ServletFilter to enforce that all page requests both aquire the lock
and MOST IMPORTANTLY finall release the lock, even in situations where there
is an exception or error on the page request.

I think someone wrote up a detailed explaination of the Load Control filter
on TheServerside.com.

Doug Bateman

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to