You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by me...@apache.org on 2009/04/05 14:28:51 UTC

svn commit: r762077 - in /incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH: ChangeLog src/com/ecyrd/jspwiki/Release.java src/com/ecyrd/jspwiki/util/WatchDog.java

Author: metskem
Date: Sun Apr  5 12:28:51 2009
New Revision: 762077

URL: http://svn.apache.org/viewvc?rev=762077&view=rev
Log:
* 2.8.3-svn-2
        * added some code to Watchdog so that the stacktrace is dumped in case of 
           a timeout, we dump stacktraces of all threads if the debuglevel is
           INFO or higher

Modified:
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/util/WatchDog.java

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog?rev=762077&r1=762076&r2=762077&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/ChangeLog Sun Apr  5 12:28:51 2009
@@ -1,3 +1,11 @@
+2009-04-05 Harry Metske <me...@apache.org>
+
+        * 2.8.3-svn-2
+
+        * added some code to Watchdog so that the stacktrace is dumped in case of 
+           a timeout, we dump stacktraces of all threads if the debuglevel is
+           INFO or higher
+        
 2008-04-04  Janne Jalkanen <ja...@apache.org>
 
         * 2.8.3-svn-1

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java?rev=762077&r1=762076&r2=762077&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/Release.java Sun Apr  5 12:28:51 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "1";
+    public static final String     BUILD         = "2";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/util/WatchDog.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/util/WatchDog.java?rev=762077&r1=762076&r2=762077&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/util/WatchDog.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_8_BRANCH/src/com/ecyrd/jspwiki/util/WatchDog.java Sun Apr  5 12:28:51 2009
@@ -54,7 +54,7 @@
     private boolean   m_enabled    = true;
     private WikiEngine m_engine;
 
-    private Logger log = Logger.getLogger(WatchDog.class.getName());
+    private static final Logger log = Logger.getLogger(WatchDog.class.getName());
 
     private static HashMap<Integer,WeakReference<WatchDog>> c_kennel = 
         new HashMap<Integer,WeakReference<WatchDog>>();
@@ -302,13 +302,11 @@
 
                 if( now > st.getExpiryTime() )
                 {
-                    log.info("Watchable '"+m_watchable.getName()+
-                             "' exceeded timeout in state '"+
-                             st.getState()+
-                             "' by "+
-                             (now-st.getExpiryTime())/1000+" seconds");
+                    log.info("Watchable '" + m_watchable.getName() + "' exceeded timeout in state '" + st.getState() + "' by "
+                             + (now - st.getExpiryTime()) / 1000 + " seconds");
 
-                    m_watchable.timeoutExceeded( st.getState() );
+                    dumpStackTraceForWatchable();
+                    m_watchable.timeoutExceeded(st.getState());
                 }
             }
             catch( EmptyStackException e )
@@ -318,6 +316,35 @@
         }
     }
 
+    private void dumpStackTraceForWatchable()
+    {
+        Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
+        Set<Thread> threads = stackTraces.keySet();
+        Iterator<Thread> threadIterator = threads.iterator();
+        while ( threadIterator.hasNext() )
+        {
+            Thread t = threadIterator.next();
+            if( t.getName().equals( m_watchable.getName() ) || log.isInfoEnabled() )
+            {
+                if( t.getName().equals( m_watchable.getName() ) )
+                {
+                    log.error( "dumping stacktrace for too long running thread : " + t );
+                }
+                else
+                {
+                    log.error( "dumping stacktrace for other running thread : " + t );
+                }
+                StackTraceElement[] ste = stackTraces.get( t );
+                StringBuilder stacktrace = new StringBuilder( "stacktrace follows" );
+                for( int i = 0; i < ste.length; i++ )
+                {
+                    stacktrace.append( "\n" + ste[i] );
+                }
+                log.error( stacktrace.toString() );
+            }
+        }
+    }
+
     /**
      *  Strictly for debugging/informative purposes.
      *
@@ -346,7 +373,7 @@
     private static class WatchDogThread extends WikiBackgroundThread
     {
         /** How often the watchdog thread should wake up (in seconds) */
-        private static final int CHECK_INTERVAL = 30;
+        private static final int CHECK_INTERVAL = 5;
 
         public WatchDogThread( WikiEngine engine )
         {