Meaningless Drivel is fun!
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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Life of Idempotency" Watch "Life of Idempotency" New topic

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

Joined: Mar 22, 2000
Posts: 13018
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.

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 ?

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213

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 -
I agree. Here's the link:
subject: Life of Idempotency
It's not a secret anymore!