abc
abc

Reputation:

how to handle browser closing event in servlets

i am having the html page in my web application. The page is locked by a client and unlocked by the same client. if the client forgets to unlock or close the browser, press back button on the page, and other links the page will locked always and cannot be unlocked. i need to unlock the page in the above cases if he forget to unlock Thanks

Upvotes: 0

Views: 674

Answers (2)

Kevin Day
Kevin Day

Reputation: 16383

I would suggest that you consider a design more appropriate to the operating characteristics of your environment.

Instead of locking and unlocking in separate transactions (which is what you have now), consider a form of optimistic locking - basically, allow anyone to have access to the data, but if they submit a modification after another user has submitted a modification to the same data, reject and give the user an opportunity to make their change again.

Having a user/client explicitly lock and unlock is easy to code, but hard to use (and we do all care about out users' experience!) Cheerio.

Upvotes: 1

Kai Huppmann
Kai Huppmann

Reputation: 10775

Specify a timeout for the lock. Since http is stateless you can't observe the client the "normal way".

EDIT: I'd protocol activity per client/lock on serverside by setting/observing some bool flag. A TimerTask is observing the flag periodically, setting the flag to false if it's true and kills the lock if it's false.

Upvotes: 1

Related Questions