GeeCON Prague 2014*
The moose likes Servlets and the fly likes Life of Idempotency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Life of Idempotency" Watch "Life of Idempotency" New topic
Author

Life of Idempotency

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Howdy Ranchers,

I was reading K&B Head First and i came across issue of Non-Idempotent request. I want to know how the problem can be stopped. I mean, Its obvious that the user of the site would feel to click SUBMIT button more then once and if it really debits then its a BOMB for the developer.

Since, every request is given a new request / response thread, how would there be a way to identify multiple same requests from the same client that too erroneous just because the net connection was slow in responding or probably due to very bad code which takes time in responding to user request ?

This issue might also occur due to temporary link breakdown and infamous "Page cannot be found" and then user pressing the back button to submit the same request again ? I am really looking forward to know this ?

Thanks in advance,
Yogendra N Joshi.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
The problem of multiple requests shows why you may want to synchronize on the Session object. The first request to grab the session object can use it to record the current state of the application. When subsequent requests can obtain access they will see that the state has already been changed.

Bill
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi Bill,

Thanks for your response. Great to know the synchronization part, can you give me more details on the implementation ?

Regards,
Yogendra
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi,

Can anyone please help me on this?

Thanks in advance.
Yogendra Joshi
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Well, synchronize on the session object and before you update any data check if it has not been updated before.




Another client side way to prevent a user from clicking the submit button more than once is disabling it immediately after the click using javascript.


JDBCSupport - An easy to use, light-weight JDBC framework -
 
GeeCON Prague 2014
 
subject: Life of Idempotency