Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-535

Thread bug in FileAlterationMonitor#stop(int)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.7
    • Component/s: Utilities
    • Environment:

      Components managed by a DI Framework

      Description

      The thread in FileAlterationMonitor wasn't stopped by the `stop(int)` method, which forbid application to shutdown until all `Thread` are exited (if FileAlterationMonitor is part of a DI managed component).

      This behavior conflict with the method javadoc `@param stopInterval the amount of time in milliseconds to wait for the thread to finish.`

      Simple example to understand

      Bad behavior

          Thread t = new Thread(() -> {
              try {
                  Thread.sleep(500000);
              } catch (final InterruptedException e) {
              }
          });
          t.start();
          t.join(50);
         // Ok, we reach this point until 500000ms are elapsed, but the thread is still alive.
         //   because Thread#join(int) does not kill the thread. And the thread remains alive.
      

      Good behavior

          Thread t = new Thread(() -> {
              try {
                  Thread.sleep(500000);
              } catch (final InterruptedException e) {
              }
          });
          t.start();
          t.join(50);
          t.interupt();
         // Thread is exited
      

      In this case, we waited the given time BEFORE exiting the `Thread`, as described in the javadoc, and the `Thread` is now finished and killed.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pascalschumacher Pascal Schumacher
                Reporter:
                anthonyraymond Anthony RAYMOND
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 5m
                  5m
                  Remaining:
                  Remaining Estimate - 5m
                  5m
                  Logged:
                  Time Spent - Not Specified
                  Not Specified