Author: kkolinko
Date: Wed Jun 20 08:55:40 2012
New Revision: 1351997
URL: http://svn.apache.org/viewvc?rev=1351997&view=rev
Log:
Merged revisions r1351991, r1351993 from tomcat/trunk:
For https://issues.apache.org/bugzilla/show_bug.cgi?id=50306
Improve StuckThreadDetectionValve:
- Add getStuckThreadNames() method, callable through JMX
- Add thread ids to the log messages
I also removed the @author tag, as that is against our policies.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings_es.properties
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
tomcat/tc7.0.x/trunk/webapps/docs/config/valve.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1351991,1351993
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings.properties
Wed Jun 20 08:55:40 2012
@@ -52,8 +52,8 @@ sslValve.certError=Failed to process cer
sslValve.invalidProvider=The SSL provider specified on the connector
associated with this request of [{0}] is invalid. The certificate data could
not be processed.
#Stuck thread detection Valve
-stuckThreadDetectionValve.notifyStuckThreadDetected=Thread "{0}" has been
active for {1} milliseconds (since {2}) to serve the same request for {4} and
may be stuck (configured threshold for this StuckThreadDetectionValve is {5}
seconds). There is/are {3} thread(s) in total that are monitored by this Valve
and may be stuck.
-stuckThreadDetectionValve.notifyStuckThreadCompleted=Thread "{0}" was
previously reported to be stuck but has completed. It was active for
approximately {1} milliseconds.{2,choice,0#|0< There is/are still {2} thread(s)
that are monitored by this Valve and may be stuck.}
+stuckThreadDetectionValve.notifyStuckThreadDetected=Thread "{0}" (id={6}) has
been active for {1} milliseconds (since {2}) to serve the same request for {4}
and may be stuck (configured threshold for this StuckThreadDetectionValve is
{5} seconds). There is/are {3} thread(s) in total that are monitored by this
Valve and may be stuck.
+stuckThreadDetectionValve.notifyStuckThreadCompleted=Thread "{0}" (id={3}) was
previously reported to be stuck but has completed. It was active for
approximately {1} milliseconds.{2,choice,0#|0< There is/are still {2} thread(s)
that are monitored by this Valve and may be stuck.}
# HTTP status reports
http.100=The client may continue ({0}).
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings_es.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings_es.properties?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings_es.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/LocalStrings_es.properties
Wed Jun 20 08:55:40 2012
@@ -37,8 +37,8 @@ remoteIpValve.syntax = Se han suministra
remoteIpValve.invalidPortHeader = Valor inv\u00E1lido [{0}] hallado para el
puerto en cabecera HTTP [{1}]
sslValve.certError = No pude procesar cadena de certificado [{0}] para crear
un objeto java.security.cert.X509Certificate
sslValve.invalidProvider = El proveedor de SSL especificado en el conecto
asociado con este requerimiento de [{0}] ies inv\u00E1lido. No se pueden
procesar los datos del certificado.
-stuckThreadDetectionValve.notifyStuckThreadDetected = El hilo "{0}" ha estado
activo durante {1} miilisegundos (desde {2}) para servir el mismo requerimiento
para {4} y puede estar atascado (el umbral configurado para este
StuckThreadDetectionValve es de {5} segundos). Hay {3} hilo(s) en total que son
monitorizados por esta V\u00E1lvula y pueden estar atascados.
-stuckThreadDetectionValve.notifyStuckThreadCompleted = El hilo "{0}", que
previamente se report\u00F3 como atascado, se ha completado. Estuvo activo por
aproximadamente {1} milisegundos. {2, choice,0\#|0< Hay a\u00FAn {2} hilo(s)
que son monitorizados por esta V\u00E1lvula y pueden estar atascados.}
+stuckThreadDetectionValve.notifyStuckThreadDetected = El hilo "{0}" (id={6})
ha estado activo durante {1} miilisegundos (desde {2}) para servir el mismo
requerimiento para {4} y puede estar atascado (el umbral configurado para este
StuckThreadDetectionValve es de {5} segundos). Hay {3} hilo(s) en total que son
monitorizados por esta V\u00E1lvula y pueden estar atascados.
+stuckThreadDetectionValve.notifyStuckThreadCompleted = El hilo "{0}" (id={3}),
que previamente se report\u00F3 como atascado, se ha completado. Estuvo activo
por aproximadamente {1} milisegundos. {2, choice,0\#|0< Hay a\u00FAn {2}
hilo(s) que son monitorizados por esta V\u00E1lvula y pueden estar atascados.}
# HTTP status reports
http.100 = El cliente puede continuar ({0}).
http.101 = El servidor est\u00E1 conmutando protocolos con arreglo a la
cabecera "Upgrade" ({0}).
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/StuckThreadDetectionValve.java
Wed Jun 20 08:55:40 2012
@@ -35,12 +35,8 @@ import org.apache.juli.logging.LogFactor
import org.apache.tomcat.util.res.StringManager;
/**
- * This valve allows to detect requests that take a long time to process,
which might
- * indicate that the thread that is processing it is stuck.
- * Based on code proposed by TomLu in Bugzilla entry #50306
- *
- * @author slaurent
- *
+ * This valve allows to detect requests that take a long time to process, which
+ * might indicate that the thread that is processing it is stuck.
*/
public class StuckThreadDetectionValve extends ValveBase {
@@ -136,10 +132,14 @@ public class StuckThreadDetectionValve e
if (log.isWarnEnabled()) {
String msg = sm.getString(
"stuckThreadDetectionValve.notifyStuckThreadDetected",
- monitoredThread.getThread().getName(),
Long.valueOf(activeTime),
+ monitoredThread.getThread().getName(),
+ Long.valueOf(activeTime),
monitoredThread.getStartTime(),
Integer.valueOf(numStuckThreads),
- monitoredThread.getRequestUri(), Integer.valueOf(threshold));
+ monitoredThread.getRequestUri(),
+ Integer.valueOf(threshold),
+ String.valueOf(monitoredThread.getThread().getId())
+ );
// msg += "\n" + getStackTraceAsString(trace);
Throwable th = new Throwable();
th.setStackTrace(monitoredThread.getThread().getStackTrace());
@@ -147,13 +147,15 @@ public class StuckThreadDetectionValve e
}
}
- private void notifyStuckThreadCompleted(String threadName,
- long activeTime, int numStuckThreads) {
+ private void notifyStuckThreadCompleted(CompletedStuckThread thread,
+ int numStuckThreads) {
if (log.isWarnEnabled()) {
String msg = sm.getString(
"stuckThreadDetectionValve.notifyStuckThreadCompleted",
- threadName, Long.valueOf(activeTime),
- Integer.valueOf(numStuckThreads));
+ thread.getName(),
+ Long.valueOf(thread.getTotalActiveTime()),
+ Integer.valueOf(numStuckThreads),
+ String.valueOf(thread.getId()));
// Since the "stuck thread notification" is warn, this should also
// be warn
log.warn(msg);
@@ -193,7 +195,7 @@ public class StuckThreadDetectionValve e
activeThreads.remove(key);
if (monitoredThread.markAsDone() == MonitoredThreadState.STUCK) {
completedStuckThreadsQueue.add(
- new
CompletedStuckThread(monitoredThread.getThread().getName(),
+ new CompletedStuckThread(monitoredThread.getThread(),
monitoredThread.getActiveTimeInMillis()));
}
}
@@ -220,8 +222,7 @@ public class StuckThreadDetectionValve e
completedStuckThread != null; completedStuckThread =
completedStuckThreadsQueue.poll()) {
int numStuckThreads = stuckCount.decrementAndGet();
- notifyStuckThreadCompleted(completedStuckThread.getName(),
- completedStuckThread.getTotalActiveTime(),
numStuckThreads);
+ notifyStuckThreadCompleted(completedStuckThread, numStuckThreads);
}
}
@@ -240,6 +241,16 @@ public class StuckThreadDetectionValve e
return result;
}
+ public String[] getStuckThreadNames() {
+ List<String> nameList = new ArrayList<String>();
+ for (MonitoredThread monitoredThread : activeThreads.values()) {
+ if (monitoredThread.isMarkedAsStuck()) {
+ nameList.add(monitoredThread.getThread().getName());
+ }
+ }
+ return nameList.toArray(new String[nameList.size()]);
+ }
+
private static class MonitoredThread {
/**
@@ -291,10 +302,12 @@ public class StuckThreadDetectionValve e
private static class CompletedStuckThread {
private final String threadName;
+ private final long threadId;
private final long totalActiveTime;
- public CompletedStuckThread(String threadName, long totalActiveTime) {
- this.threadName = threadName;
+ public CompletedStuckThread(Thread thread, long totalActiveTime) {
+ this.threadName = thread.getName();
+ this.threadId = thread.getId();
this.totalActiveTime = totalActiveTime;
}
@@ -302,6 +315,10 @@ public class StuckThreadDetectionValve e
return this.threadName;
}
+ public long getId() {
+ return this.threadId;
+ }
+
public long getTotalActiveTime() {
return this.totalActiveTime;
}
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/valves/mbeans-descriptors.xml
Wed Jun 20 08:55:40 2012
@@ -536,10 +536,15 @@
writeable="false"/>
<attribute name="stuckThreadIds"
- description="IDs of the thread currently considered stuck. Each
ID can then be used with the ThreadMXBean to retrieve data about it."
+ description="IDs of the threads currently considered stuck.
Each ID can then be used with the Threading MBean to retrieve data about it."
type="long[]"
writeable="false"/>
+ <attribute name="stuckThreadNames"
+ description="Names of the threads currently considered stuck."
+ type="java.lang.String[]"
+ writeable="false"/>
+
<attribute name="threshold"
description="Duration in seconds after which a request is
considered as stuck"
type="int"/>
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Jun 20 08:55:40 2012
@@ -60,6 +60,11 @@
Fix checking of recommended tcnative library version when using the APR
connector. (rjung)
</fix>
+ <update>
+ <bug>50306</bug>: Improve StuckThreadDetectionValve: add
+ stuckThreadNames property as a pair for the stuckThreadIds one,
+ add thread ids to the log messages. (kkolinko)
+ </update>
</changelog>
</subsection>
<subsection name="Web applications">
Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/valve.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/valve.xml?rev=1351997&r1=1351996&r2=1351997&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/valve.xml Wed Jun 20 08:55:40 2012
@@ -1444,9 +1444,11 @@
indicate that the thread that is processing it is stuck.</p>
<p>When such a request is detected, the current stack trace of its thread
is written
to Tomcat log with a WARN level.</p>
- <p>The IDs of the stuck threads are available through JMX in the
- <code>stuckThreadIds</code> attribute. The JVM Thread MBean can then be
used to
- retrieve other information about each stuck thread (name, stack
trace...).</p>
+ <p>The IDs and names of the stuck threads are available through JMX in the
+ <code>stuckThreadIds</code> and <code>stuckThreadNames</code> attributes.
+ The IDs can be used with the standard Threading JVM MBean
+ (<code>java.lang:type=Threading</code>) to retrieve other information
+ about each stuck thread.</p>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]