浏览代码

HADOOP-1898. Release the lock protecting the last time of the last stack
dump while the dump is happening. Contributed by Amareshwari Sri Ramadasu.


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@588083 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 17 年之前
父节点
当前提交
0167e70c01
共有 2 个文件被更改,包括 17 次插入6 次删除
  1. 5 0
      CHANGES.txt
  2. 12 6
      src/java/org/apache/hadoop/util/ReflectionUtils.java

+ 5 - 0
CHANGES.txt

@@ -24,6 +24,11 @@ Trunk (unreleased changes)
     HADOOP-1604.  An system administrator can finalize namenode upgrades 
     without running the cluster. (Konstantin Shvachko via dhruba)
 
+  OPTIMIZATIONS
+
+    HADOOP-1898.  Release the lock protecting the last time of the last stack
+    dump while the dump is happening. (Amareshwari Sri Ramadasu via omalley)
+
 Branch 0.15 (unreleased changes)
 
   INCOMPATIBLE CHANGES

+ 12 - 6
src/java/org/apache/hadoop/util/ReflectionUtils.java

@@ -151,13 +151,19 @@ public class ReflectionUtils {
    * @param title a descriptive title for the call stacks
    * @param minInterval the minimum time from the last 
    */
-  public static synchronized void logThreadInfo(Log log,
-                                                String title,
-                                                long minInterval) {
+  public static void logThreadInfo(Log log,
+                                   String title,
+                                   long minInterval) {
+    boolean dumpStack = false;
     if (log.isInfoEnabled()) {
-      long now = System.currentTimeMillis();
-      if (now - previousLogTime >= minInterval * 1000) {
-        previousLogTime = now;
+      synchronized (ReflectionUtils.class) {
+        long now = System.currentTimeMillis();
+        if (now - previousLogTime >= minInterval * 1000) {
+          previousLogTime = now;
+          dumpStack = true;
+        }
+      }
+      if (dumpStack) {
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         printThreadInfo(new PrintWriter(buffer), title);
         log.info(buffer.toString());