Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Notify servlet prior to session invalidate

 
Jeff Satori
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Background Info:
I am working on a project to lock a product id number so it may not be accessed by more than one session at a time. I create a lock by writing the session id, product id number, user id and timestamp to a oracle database table.
What I am trying to do is release the lock when the user ends their session by closing a browser.
Question:
When a session is going to be invalidated because time out interval has been reached, is there a way to call a servlet to perform a "release lock" function?
By the way, I am using Websphere 3.0.2 and Java 1.1.7
 
Jeff Satori
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I figured out that I should use the HttpSessionBindListener.valueUnbound method but I am still unsure about the syntax which adds the listener to the the session. Could someone help me out with this?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Satori:
OK, I figured out that I should use the HttpSessionBindListener.valueUnbound method but I am still unsure about the syntax which adds the listener to the the session. Could someone help me out with this?

req.getSession().setAttribute("bean", bean). Provided your bean implements HttpSessionBindingListener, it will be called automagically when it is unbound or the session expires.
You might want to look into the DBMS_LOCK package, by the way.
- Peter
 
Jeff Satori
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Peter, that did the trick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic