Hi Chris,

The initial submitter had a HttpServlet implementing ServletContextListener with a non static timer, and in fact there were 2 instances of the class: the contextDestroyed method of the servletContextListener instance can't cancel the timer of the httpServlet instance (NullPointerException as he said) then Tomcat 6.0.26 stopped the leak. As Pid said there is a mix and match. To fix it, the init and destroy methods of the HttpServlet can create and cancel the timer cleanly (no more NullPointerException and no more leak).

Then I just wanted to suggest a finally and a cancel in the init method to be cleaner (because if there is an OutOfMemoryError or something like that in scheduleAtFixedRate, then the leak appears again except that Tomcat 6.0.26 stops it. Thanks Konstantin).

bye, Emeric


Le 26/05/2010 22:33, Christopher Schultz a écrit :
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Emeric,

On 5/26/2010 3:52 PM, Emeric Vernat wrote:
You could also eliminate the mix&  match and add a finally, with the
following servlet code for example:

public void init() throws ServletException {
                boolean initOk = false;
         mytimer = new Timer("__test__");
                 try {
             TimerTask taskPerformer = new TimerTask() { public void
run() { whatever_function(); } };
                        mytimer.scheduleAtFixedRate(taskPerformer, 10,
10, 864000);
                         testint = 12;
             initOk = true; // as last
         } finally {
             if (!initOk) {
                 mytimer.cancel();
             }
         }
          }
Uh.... what? I'm sure that does something, but ... I'm not sure what it
could be.

Could the OP show us the stack trace relative to the warning coming from
Tomcat? I'd bet that Tomcat's "stop leaks" procedure is clearing-out a
static Timer reference and /then/ the ServletContextListener is trying
to access it. That's not supposed to happen, I'm guessing: the "stop
leaks" stuff should run after all ServletContextListeners been notified
that the context is coming down.

I'm sure there is more useful information in the log file that we're not
seeing.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv9haYACgkQ9CaO5/Lv0PCM1QCgvc2Y/SD1UJntGSBMJzo7ThBx
Ty8An3wul/JusKxqjB3fRZRdikJjdI8l
=z2/W
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org







---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to