File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to make an object strongly reachable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to make an object strongly reachable?" Watch "How to make an object strongly reachable?" New topic
Author

How to make an object strongly reachable?

William Shubert
Greenhorn

Joined: Mar 30, 2004
Posts: 2
I've got a JSP problem (Tomcat 5.0.19). I use a Timer object to kick off occasional actions in my JSP engine - flushing cached information, pinging my RMI peers, etc. My timers sometimes complain about "Timer already stopped" when I try to schedule a new event. A little digging shows that this can happen when a the JVM tries to garbage collect a timer. This is absurd, my timer object is in the application scope, it should never even begin to be garbage collected!
How do I make sure that the timer is always strongly reachable? I've tried using daemon and non-daemon timers, tried adding static references to the timer - nothing seems to work.
Here's the code that makes the timer:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

You are correct in that an object in application scope should never be garbage collected. The map implementing the attribute list in the servlet context object will retain a reference to the object. There must be some other subtle factor at play here.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Shubert
Greenhorn

Joined: Mar 30, 2004
Posts: 2
Just to be 100% clear - actually, the timers are not being garbage collected, but their finalizer is being called. It is the calling of the finalizer that cancels the timers even though I am still using it.
So the real question is, why is the finalizer of an application scoped object being called? And how do I stop this from happening?
For now I have a workaround. I have created a class that extends timers, and uses a delegate "real" timer. When it gets an IllegalStateException thrown from the "real" timer, then I just create a new one and start giving all my scheduled tasks to that. It's an ugly solution, so I'd like something better, but for now it works.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Try using Quartz instead of writing your own: http://www.quartzscheduler.org/quartz/
brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make an object strongly reachable?
 
Similar Threads
Garbage Collection
String x = "hi" ; garbage collected ?
Who clean up finished Timer's threads?
Assign variable value to object name?
Need to restart timer with different time