This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setMaxInactiveInterval() finalize()

 
Thomas Rochon
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !
Maybe that question occured somewhere else
in this faq. But I didn't found it.
So - Here is my problem :
I create a session object in a servlet class.
I set the MaxInactiveInterval of the session
object to 15 minutes.
After the 15 minutes have expired the servlet should call a method. I put the method finalize()
into the servlet. Looks something like that:
protected void finalize() {
// call a method
}
The problem is, after 15 Minutes (30 minutes, whatever) nothing happens. No method call and even no System.out. Nothing.
So - What's wrong ?
Cans please someone help me ?
Thanx !
Thomas
 
David Brafford
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Servlet version does your web container
support?
If 2.3, you can use an HttpSessionListener to
listen when a session is created, and when a
session is destroyed.
void sessionCreated(HttpSessionEvent e)
void sessionDestroyed(HttpSessionEvent e)
The new LifeCycle events were added in the
Servlet 2.3 specification
-------------------------------------------
Considering the Certified Java Programmer Exam?
Get JCertify!
Now available for Exam 310-035 and 310-025
http://www.enterprisedeveloper.com/jcertify
 
Tracy Woo
Ranch Hand
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Rochon:
After the 15 minutes have expired the servlet should call a method.

Why should the servlet call a method??? When the session expires, the servlet container will call sessionDestroyed() on a HttpSessionListener [needs to be configured in the DD]
Also, finalize() on the servlet will not be called till the servlet object is about to be destroyed by the GC. You should not depend on that. And it has nothing to with sessions anyway.
 
Thomas Rochon
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies !
I'll try to solve the problem with the HttpSessionListener, like David told me. I red some tutorials on that and it sounds like that's the right way to go.
I'm very new with java, servlets a.s.o. .
So please keep your fingers crossed that I'll get it
Thanks a lot !
- Thomas -
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas, here is some sample code in case you are interested.
 
Thomas Rochon
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ups - Today I noticed that you posted a reply to my Question. Well it's long ago. But .... Thanx )
I had to solve the problem another way, because the Websphere Application Server I'm using doesn't suppoert the servlet 2.3 spezification yet.
But thanx for your reply )
- Thomas -
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic