tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Thread Dumps/ Emailing Results...
Date Tue, 04 Nov 2008 21:44:35 GMT
Hash: SHA1


Caldarale, Charles R wrote:
>> From: keeplearning []
>> Subject: Thread Dumps/ Emailing Results...
>> So, do i need to supply process id with this command. Like:
>> kill -3 <process id>.
> That's one way to do it.  My preference is to use the jstack tool from the JDK, assuming
you're running a 1.5 or 1.6 Sun JVM.

I have written a script to check for OOMs by checking catalina.out for
"OutOfMemoryError". When such an error is detected, I run the following
commands (apologies for the line wrapping):

APP_PID=[fill this in with a way to get your app's pid]
  # Make sure the pid looks like a pid
  if [ "${APP_PID}" != `expr match "${APP_PID}" '\([0-9]\+\)'` ] ; then
    echo "Could not determine the correct pid for ${APP_NAME}" >> ${OUTPUT}
    # Make sure that this pid belongs to the proper process
    ps -e x | grep "^[ \t]*${APP_PID}.*${PROCESS_STRING}" > /dev/null

    if [ "$?" == "0" ] ; then
      # This is the correct pid

      if [ -x ${JSTACK} ] ; then
         # jstack is available on the system: this is way easier

         echo '=============== THREAD DUMP =================' >> ${OUTPUT}
         ${JSTACK} ${APP_PID} >> "${OUTPUT}" 2>&1
         # Generate a thread dump on the java process
         kill -QUIT ${APP_PID}

         # Now, go find that thread dump in the log file
         echo '=============== THREAD DUMP =================' >> ${OUTPUT}
         dump_start_line=`grep -n '^Full thread' ${LOGFILE} | tail -n 1
| sed -e
         tail -n +${dump_start_line} ${LOGFILE} >> ${OUTPUT}

      # What the heck, let's get a heap dump, too.
      echo '================ HEAP SUMMARY ===================' >> ${OUTPUT}
      ${JMAP} -heap ${APP_PID} >> ${OUTPUT} 2>&1

      echo '================ OBJECT HISTOGRAM ===============' >> ${OUTPUT}
      ${JMAP} -histo ${APP_PID} >> ${OUTPUT} 2>&1
      echo 'Could not determine the correct pid for ${APP_NAME}' >>

  mail -s "Found OOME in ${APP_NAME}!" ${ADMIN_EMAIL} < ${OUTPUT}


If jstack isn't available, we use a hack to generate a thread dump and
extract it from catalina.out.

> You still need the process id, and the JDK includes the jps tool
> which is easier than wading through the output of ps.  The JDK tools
> also work on Windows, whereas kill doesn't normally exist there.

Yes, this is a UNIX-specific script, unless you want to run it on Cygwin
(untested, by the way). But, if you're running on Windows, you don't
really care about uptime, anyway, do you? ;)

Hope that helps,
- -chris
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla -


To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message