tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Davidson <>
Subject Re: Notification strategy for OutOfMemoryError
Date Fri, 24 Jan 2014 18:44:15 GMT
On 1/23/2014 5:21 PM, Christopher Schultz wrote:
 >If you'd care to post your code to either the list or onto the wiki, I'm
 >sure it would be useful to someone. Feel free to trim-out huge sections
 >of the code and say "make this fit your environment", etc. if you don't
 >want to show everyone how bad your email-assembling code looks ;)

Yeah, I don't really want to show my email code.  Sending email
will be left as an exercise for the reader.

The filter part of it is barely anything.  The method
handleError(Error,ServletRequest) does the work of logging and
sending email.  I synchronized that method so that only one can
run at a time in order to minimize memory usage by the filter
if I'm getting multiple Error's thrown.

      * Catch all {@link Throwable}s and notify on {@link Error}s.
      * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain
) throws IOException, ServletException
             chain.doFilter(request, response);
         }catch ( Throwable t ){
             if ( t instanceof Error ){
                     handleError((Error)t, request);
                 }catch ( Throwable tx ){
                     m_log.fatal(tx.getMessage(), tx);
             throw t;

     private static synchronized void handleError( Error error, ServletRequest request ) throws
UnsupportedEncodingException, MessagingException
          <log and check the error and send email>

There are also destroy() and init(FilterConfig) methods but they are stubs
that do nothing and are only there because they are required by the Filter


     <!-- Filter to catch java.lang.Error and send emails -->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message