Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-4613

hbase.util.Threads#threadDumpingIsAlive sleeps 1 second, slowing down the shutdown by 0.5s

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 0.94.0
    • Fix Version/s: 0.92.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      all

    • Hadoop Flags:
      Reviewed

      Description

      Current implementation is:

       
        /**
         * @param t Waits on the passed thread to die dumping a threaddump every
         * minute while its up.
         * @throws InterruptedException
         */
        public static void threadDumpingIsAlive(final Thread t)
        throws InterruptedException {
          if (t == null) {
            return;
          }
          long startTime = System.currentTimeMillis();
          while (t.isAlive()) {
            Thread.sleep(1000);
            if (System.currentTimeMillis() - startTime > 60000) {
              startTime = System.currentTimeMillis();
              ReflectionUtils.printThreadInfo(new PrintWriter(System.out),
                  "Automatic Stack Trace every 60 seconds waiting on " +
                  t.getName());
            }
          }
        }
      

      while this one would make more sense considering the documentation, and save around 0,5s when the MiniCluster shutdowns.

        public static void threadDumpingIsAlive(final Thread t)
          throws InterruptedException {
          if (t == null) {
            return;
          }
      
          while (t.isAlive()) {
            t.join(60 * 1000);
            if (t.isAlive()) {
              ReflectionUtils.printThreadInfo(new PrintWriter(System.out),
                "Automatic Stack Trace every 60 seconds waiting on " +
                  t.getName());
            }
          }
        }
      

      However, it was replacing a previous implementation with a join without a timeout. So if anyone has a warning here...
      Tests seems to be ok...

        Attachments

        1. 20111020_4613_Threads.patch
          0.8 kB
          Nicolas Liochon

          Issue Links

            Activity

              People

              • Assignee:
                nkeywal Nicolas Liochon
                Reporter:
                nkeywal Nicolas Liochon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: