Remember: Examples are Just Examples

For example, the documentation at Using the WebLogic Server JMX Timer Service gives a very straight-forward and standards-compliant example of how to run a task at intervals.  I used this example almost in its entirety to create a module to poll a database for a specific change every 2o minutes. I then noticed that the timer would stop for no apparent reason at no obvious interval.

After many hours of digging through logs looking for some cause, I was ready to give in and post a plea for help on a mailing list. It just so happened used a text editor to grab the code to post, and noticed in the text editor that there was one place where unregister would be called on the bean: under contextDestroyed in the servlet to at registered the timer.  In the clarity of hind-sight I realized that the timer was stopping more often in environments that were accessed less often because the efficient WebLogic Server was garbage collecting the unused servlet handle, resulting in contextDestroyed being invoked, thus killing my timer. As it normally should, except in the case where the timer should continue running as long as the server was running.

Lesson learned: Think it all the way through between copy and paste.

For those who like links and confessions:  There is an example of using a timer in my JavaBoutique article that contains precisely the same flaw in logic.

Facebooktwitterredditlinkedinmail
© Scott S. Nelson

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.