Skip to content

Commit 1efc3cf

Browse files
author
Niall Pemberton
committed
IO-259 - add stop(long) method that specifies the amount of time to wait before stopping the monitor - thanks to Dan Checkoway
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1080843 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8ff60c3 commit 1efc3cf

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/java/org/apache/commons/io/monitor/FileAlterationMonitor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,29 @@ public synchronized void start() throws Exception {
147147
* @throws Exception if an error occurs initializing the observer
148148
*/
149149
public synchronized void stop() throws Exception {
150+
stop(interval);
151+
}
152+
153+
/**
154+
* Stop monitoring.
155+
*
156+
* @param stopInterval the amount of time in milliseconds to wait for the thread to finish.
157+
* A value of zero will wait until the thread to finished (see {@link Thread#join(long)})
158+
* and a nagative value will stop the process immediately).
159+
* @throws Exception if an error occurs initializing the observer
160+
* @since Commons IO 2.1
161+
*/
162+
public synchronized void stop(long stopInterval) throws Exception {
150163
if (running == false) {
151164
throw new IllegalStateException("Monitor is not running");
152165
}
153166
running = false;
154167
try {
155-
thread.join(interval);
168+
if (stopInterval < 0) {
169+
thread.interrupt();
170+
} else {
171+
thread.join(stopInterval);
172+
}
156173
} catch (InterruptedException e) {
157174
Thread.currentThread().interrupt();
158175
}

0 commit comments

Comments
 (0)