FileAlternationMonitor#stop() does not stop the thread#36
FileAlternationMonitor#stop() does not stop the thread#36anthonyraymond wants to merge 1 commit into
Conversation
|
Jira issue : https://issues.apache.org/jira/browse/IO-535 |
| thread.join(stopInterval); | ||
| thread.interrupt(); | ||
| } catch (final InterruptedException e) { | ||
| Thread.currentThread().interrupt(); |
There was a problem hiding this comment.
Is swallowing an InterruptedException a really bad practice (at least according to Java Concurrency in Practice and https://www.ibm.com/developerworks/library/j-jtp05236/)?
There was a problem hiding this comment.
Tell me if i'm wrong, because it is kind of obscure.
The FileAlterationMonitor embed a thread. But when we call stop() we are calling from another thread (most likely the main thread).
Isn't Thread.currentThread().interrupt(); going to stop the calling thread? In our case the main thread?
Now, i agree that catching an exception to do nothing sounds dumb. But in our case we want to stop the inner thread. So even if it is interupted while performing the join() is kind of a good news. It just stopped earlier than expected.
Am i correct?
There was a problem hiding this comment.
Thank you for your PR @anthonyraymond
Regardless of the implementation of this fix, it would be great to provide a unit test that fails without the main patch. Otherwise, "confidence is low" and regression will happen.
There was a problem hiding this comment.
Hi @garydgregory .
@SvetlinZarev was faster than i was: #58
The thread if FileAlterationMonitor wasn't stopped by the
stop(int)method, which forbid application to shutdown unless allThreadare 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 why i changed the code
In this case, we waited the given time BEFORE exiting the
Thread, as described in the javadoc, and theThreadis now finished and killed.