I have an application which uses java.util.Timer and java.util.TimerTask. My code uses just one Timer, but there are 21 places in my code where I create a new TimerTask with its run() method. All these TimerTasks are scheduled using the one Timer.

I've learned the hard way that a RuntimeException thrown within any of my TimerTask run() methods kills the thread in the Timer. The Timer stops working. But the stacktrace for the RuntimeException, which might alert me to my problem, gets written into one of Tomcat's logs where I never had reason to look till now.

My impulse is to create an extension with modified behavior which catches RuntimeExceptions and writes the bad news right under my nose (onto a console and into a log which I watch regularly). So I would write this sort of thing just one place in my code:
   try{...}catch(RuntimeException e){log(e);}
But I have not thought of a neat way to do this using object oriented design.

I might get what I want by extending both Timer and TimerTask, but I thought object oriented design offered simpler ways to achieve such simple augmentations in behavior. Maybe I am overlooking something. I'm looking for suggestions.

Thank you,
Rich Hammer

_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to