Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session question - specifically Tomcat  RSS feed

 
Chris Lord
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a couple of questions about Session scope (and specifcally on Tomcat if that makes a difference). If I have an instance of myClass, and I've put it into session scope then:
1. If myClass has some call back methods (it implements some event listener Interface), will these methods get called if the events occur, but while the class instance is held by the webserver. Or similarly (and a bad example I know before anyone says!!) myClass opens up a TCPIP socket connection to something, then will it still communicate "behind the scenes" when the webserver is maintaining it.
2. If I have a finalize method on myClass, then it gets called when the webserver times out the session, but if the webserver is terminated/shutdown, should these finalize methods still get run.
Chris
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on both accounts i believe the answer to be yes
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing magic about an instance of an object being held in a session - it is still a Java object in program memory.
The only problem I can think of is that management of a session is up to the servlet engine, which is allowed to store the session by serializing it. In which case the instance would no longer live in memory.
Therefore, if you want to be absolutely sure the object hangs around to get the callback you should manage it yourself.
You should NOT count of finalize being run. You should regard finalize as a "last chance" opportunity to clean up, not the first line of defence.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!