commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1080843 - /commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
Date Sat, 12 Mar 2011 01:55:22 GMT
Author: niallp
Date: Sat Mar 12 01:55:22 2011
New Revision: 1080843

URL: http://svn.apache.org/viewvc?rev=1080843&view=rev
Log:
IO-259 - add stop(long) method that specifies the amount of time to wait before stopping the
monitor - thanks to Dan Checkoway

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java?rev=1080843&r1=1080842&r2=1080843&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java
Sat Mar 12 01:55:22 2011
@@ -147,12 +147,29 @@ public final class FileAlterationMonitor
      * @throws Exception if an error occurs initializing the observer
      */
     public synchronized void stop() throws Exception {
+        stop(interval);
+    }
+
+    /**
+     * Stop monitoring.
+     *
+     * @param stopInterval the amount of time in milliseconds to wait for the thread to finish.
+     * A value of zero will wait until the thread to finished (see {@link Thread#join(long)})
+     * and a nagative value will stop the process immediately).
+     * @throws Exception if an error occurs initializing the observer
+     * @since Commons IO 2.1
+     */
+    public synchronized void stop(long stopInterval) throws Exception {
         if (running == false) {
             throw new IllegalStateException("Monitor is not running");
         }
         running = false;
         try {
-            thread.join(interval);
+            if (stopInterval < 0) {
+                thread.interrupt();
+            } else {
+                thread.join(stopInterval);
+            }
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();
         }



Mime
View raw message