You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Morten Hattesen (JIRA)" <ji...@apache.org> on 2012/11/21 00:46:58 UTC
[jira] [Created] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Morten Hattesen created IO-357:
----------------------------------
Summary: Tailer: Interruption while sleeping is silently ignored
Key: IO-357
URL: https://issues.apache.org/jira/browse/IO-357
Project: Commons IO
Issue Type: Bug
Components: Streams/Writers
Affects Versions: 2.4
Reporter: Morten Hattesen
The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
Source snippet:
{code}
360 try {
361 Thread.sleep(delayMillis);
362 } catch (InterruptedException e) {
363 }
...
425 try {
426 Thread.sleep(delayMillis);
427 } catch (InterruptedException e) {
428 }
{code}
This is an inappropriate behavior, since it prevents controlled shutdown by a container.
This may be rectified in one of these ways:
# Declare the method as "throws InterruptedException" and eliminate the catch clause. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
# Rethrow the InterruptedException wrapped in a (subclass of) RuntimeException.
# Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501648#comment-13501648 ]
Morten Hattesen commented on IO-357:
------------------------------------
Having had another look at the code, you might also consider simply removing the tro {{InterruptedException}} catch blocks, and letting the existing catch block handle the {{InterruptException}}. That would exit the {{while}} loop, not requiring a call to {{stop()}}, and notifying the listener about the interruption:
{code}
435 } catch (Exception e) {
436 // Handles InterruptedException, too
437 listener.handle(e);
438
439 } finally {
440 IOUtils.closeQuietly(reader);
441 }
{code}
As always, the code is complete, when there is no more code to be removed ;)
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Sebb (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502017#comment-13502017 ]
Sebb commented on IO-357:
-------------------------
AFAICT there's no point calling stop outside the run loop, because the flag won't be checked.
Also InterruptedException is an instance of Exception; no point in having a separate catch unless the code is different.
So in fact the only change required would be to remove the catch blocks after Thread.sleep().
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502033#comment-13502033 ]
Gary Gregory commented on IO-357:
---------------------------------
"AFAICT there's no point calling stop outside the run loop, because the flag won't be checked."
I added a call to stop() to play nice with [IO-345]: Supply a hook method allowing Tailer actively determining stop condition.
This lets a Tailer subclass (as requested in IO-345) access the run value.
"Also InterruptedException is an instance of Exception; no point in having a separate catch unless the code is different."
The code in the two catche clauses _is_ different. For InterruptedException, interrupt() is called.
It is more obvious like this:
{noformat}
Index: src/main/java/org/apache/commons/io/input/Tailer.java
===================================================================
--- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1411980)
+++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy)
@@ -356,10 +356,7 @@
listener.fileNotFound();
}
if (reader == null) {
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
} else {
// The current position in the file
position = end ? file.length() : 0;
@@ -410,22 +407,27 @@
if (reOpen) {
IOUtils.closeQuietly(reader);
}
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
if (getRun() && reOpen) {
reader = new RandomAccessFile(file, RAF_MODE);
reader.seek(position);
}
}
- } catch (Exception e) {
- listener.handle(e);
+ } catch (InterruptedException e) {
+ stop(e);
+ Thread.currentThread().interrupt();
+ } catch (Exception e) {
+ stop(e);
} finally {
IOUtils.closeQuietly(reader);
}
}
+ private void stop(Exception e) {
+ listener.handle(e);
+ stop();
+ }
+
/**
* Allows the tailer to complete its current loop and return.
*/
{noformat}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Charles Honton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501655#comment-13501655 ]
Charles Honton commented on IO-357:
-----------------------------------
To allow calling Threads to know Tailer was stopped by interruption, use both options 2 and 3 from above:
@@ -360,6 +360,7 @@
try {
Thread.sleep(delayMillis);
} catch (InterruptedException e) {
+ stop();
+ Thread.currentThread().interrupt();
}
} else {
// The current position in the file
@@ -425,6 +426,7 @@
try {
Thread.sleep(delayMillis);
} catch (InterruptedException e) {
+ stop();
+ Thread.currentThread().interrupt();
}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501721#comment-13501721 ]
Morten Hattesen commented on IO-357:
------------------------------------
Looks good to me!
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501633#comment-13501633 ]
Gary Gregory commented on IO-357:
---------------------------------
Well, (2) sounds pretty good.
Any other thoughts?
{noformat}
Index: src/main/java/org/apache/commons/io/input/Tailer.java
===================================================================
--- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1402268)
+++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy)
@@ -360,6 +360,7 @@
try {
Thread.sleep(delayMillis);
} catch (InterruptedException e) {
+ stop();
}
} else {
// The current position in the file
@@ -425,6 +426,7 @@
try {
Thread.sleep(delayMillis);
} catch (InterruptedException e) {
+ stop();
}
if (getRun() && reOpen) {
reader = new RandomAccessFile(file, RAF_MODE);
{noformat}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502032#comment-13502032 ]
Gary Gregory commented on IO-357:
---------------------------------
"AFAICT there's no point calling stop outside the run loop, because the flag won't be checked."
I added a call to stop() to play nice with [IO-345]: Supply a hook method allowing Tailer actively determining stop condition.
This lets a Tailer subclass (as requested in IO-345) access the run value.
"Also InterruptedException is an instance of Exception; no point in having a separate catch unless the code is different."
The code in the two catche clauses _is_ different. For InterruptedException, interrupt() is called.
It is more obvious like this:
{noformat}
Index: src/main/java/org/apache/commons/io/input/Tailer.java
===================================================================
--- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1411980)
+++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy)
@@ -356,10 +356,7 @@
listener.fileNotFound();
}
if (reader == null) {
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
} else {
// The current position in the file
position = end ? file.length() : 0;
@@ -410,22 +407,27 @@
if (reOpen) {
IOUtils.closeQuietly(reader);
}
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
if (getRun() && reOpen) {
reader = new RandomAccessFile(file, RAF_MODE);
reader.seek(position);
}
}
- } catch (Exception e) {
- listener.handle(e);
+ } catch (InterruptedException e) {
+ stop(e);
+ Thread.currentThread().interrupt();
+ } catch (Exception e) {
+ stop(e);
} finally {
IOUtils.closeQuietly(reader);
}
}
+ private void stop(Exception e) {
+ listener.handle(e);
+ stop();
+ }
+
/**
* Allows the tailer to complete its current loop and return.
*/
{noformat}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Charles Honton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502036#comment-13502036 ]
Charles Honton commented on IO-357:
-----------------------------------
InterruptedException should reset the interrupt condition before calling listener.handle(e).
{code}
- } catch (Exception e) {
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
listener.handle(e);
+ } catch (Exception e) {
+ listener.handle(e);
} finally {
IOUtils.closeQuietly(reader);
}
{code}
or
{code}
} catch (Exception e) {
+ if(e instanceof InterruptedException) {
+ Thread.currentThread().interrupt();
+ }
listener.handle(e);
} finally {
IOUtils.closeQuietly(reader);
}
{code}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Morten Hattesen updated IO-357:
-------------------------------
Description:
The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
Source snippet:
{code}
360 try {
361 Thread.sleep(delayMillis);
362 } catch (InterruptedException e) {
363 }
...
425 try {
426 Thread.sleep(delayMillis);
427 } catch (InterruptedException e) {
428 }
{code}
This is an inappropriate behavior, since it prevents controlled shutdown by a container.
This may be rectified in one of these ways:
# Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
# Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
# Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
For reference, please refer to these resources about handling thread interruption:
* http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
* Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
was:
The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
Source snippet:
{code}
360 try {
361 Thread.sleep(delayMillis);
362 } catch (InterruptedException e) {
363 }
...
425 try {
426 Thread.sleep(delayMillis);
427 } catch (InterruptedException e) {
428 }
{code}
This is an inappropriate behavior, since it prevents controlled shutdown by a container.
This may be rectified in one of these ways:
# Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
# Rethrow the InterruptedException wrapped in a (subclass of) RuntimeException.
# Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}}
For reference, please refer to these resources about handling thread interruption:
* http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
* Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (IO-357) [Tailer] InterruptedException while the
thead is sleeping is silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory updated IO-357:
----------------------------
Summary: [Tailer] InterruptedException while the thead is sleeping is silently ignored (was: Tailer: InterruptedException while the thead is sleeping is silently ignored)
> [Tailer] InterruptedException while the thead is sleeping is silently ignored
> -----------------------------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (IO-357) Tailer: Interruption while
sleeping is silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501648#comment-13501648 ]
Morten Hattesen edited comment on IO-357 at 11/21/12 1:49 AM:
--------------------------------------------------------------
Having had another look at the code, you might also consider simply removing the two {{InterruptedException}} catch blocks, letting the existing catch block handle the {{InterruptException}}. That would exit the {{while}} loop, not requiring a call to {{stop()}}, and notifying the listener about the interruption:
{code}
435 } catch (Exception e) {
436 // Handles InterruptedException, too
437 listener.handle(e);
438
439 } finally {
440 IOUtils.closeQuietly(reader);
441 }
{code}
As always, the code is complete, when there is no more code to be removed ;)
was (Author: mortenh):
Having had another look at the code, you might also consider simply removing the tro {{InterruptedException}} catch blocks, and letting the existing catch block handle the {{InterruptException}}. That would exit the {{while}} loop, not requiring a call to {{stop()}}, and notifying the listener about the interruption:
{code}
435 } catch (Exception e) {
436 // Handles InterruptedException, too
437 listener.handle(e);
438
439 } finally {
440 IOUtils.closeQuietly(reader);
441 }
{code}
As always, the code is complete, when there is no more code to be removed ;)
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501639#comment-13501639 ]
Morten Hattesen commented on IO-357:
------------------------------------
That would definitely do the job.
The only minor issue would be that the calling thread would have no way of knowing that the Tailer was stopped by interruption, but I honestly don't see any situation where that would cause a major issue at all.
It should be considered to also call {{listener.handle(e)}} prior to calling {{stop()}}, which would at least give the listener a chance to discover the interruption, and possibly perform some logging etc.
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Resolved] (IO-357) [Tailer] InterruptedException while the
thead is sleeping is silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory resolved IO-357.
-----------------------------
Resolution: Fixed
Fix Version/s: 2.5
{noformat}
commit -m "[IO-358][Tailer] InterruptedException while the thread is sleeping is silently ignored." C:/svn/org/apache/commons/trunks-proper/io/src/test/java/org/apache/commons/io/input/TailerTest.java C:/svn/org/apache/commons/trunks-proper/io/src/main/java/org/apache/commons/io/input/Tailer.java C:/svn/org/apache/commons/trunks-proper/io/src/changes/changes.xml
Sending C:/svn/org/apache/commons/trunks-proper/io/src/changes/changes.xml
Sending C:/svn/org/apache/commons/trunks-proper/io/src/main/java/org/apache/commons/io/input/Tailer.java
Sending C:/svn/org/apache/commons/trunks-proper/io/src/test/java/org/apache/commons/io/input/TailerTest.java
Transmitting file data ...
Committed revision 1412391.
{noformat}
> [Tailer] InterruptedException while the thead is sleeping is silently ignored
> -----------------------------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
> Fix For: 2.5
>
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Morten Hattesen updated IO-357:
-------------------------------
Description:
The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
Source snippet:
{code}
360 try {
361 Thread.sleep(delayMillis);
362 } catch (InterruptedException e) {
363 }
...
425 try {
426 Thread.sleep(delayMillis);
427 } catch (InterruptedException e) {
428 }
{code}
This is an inappropriate behavior, since it prevents controlled shutdown by a container.
This may be rectified in one of these ways:
# Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
# Rethrow the InterruptedException wrapped in a (subclass of) RuntimeException.
# Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}}
For reference, please refer to these resources about handling thread interruption:
* http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
* Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
was:
The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
Source snippet:
{code}
360 try {
361 Thread.sleep(delayMillis);
362 } catch (InterruptedException e) {
363 }
...
425 try {
426 Thread.sleep(delayMillis);
427 } catch (InterruptedException e) {
428 }
{code}
This is an inappropriate behavior, since it prevents controlled shutdown by a container.
This may be rectified in one of these ways:
# Declare the method as "throws InterruptedException" and eliminate the catch clause. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
# Rethrow the InterruptedException wrapped in a (subclass of) RuntimeException.
# Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Rethrow the InterruptedException wrapped in a (subclass of) RuntimeException.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}}
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13502079#comment-13502079 ]
Gary Gregory commented on IO-357:
---------------------------------
Or like this:
{code:java}
Index: src/main/java/org/apache/commons/io/input/Tailer.java
===================================================================
--- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1411980)
+++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy)
@@ -356,10 +356,7 @@
listener.fileNotFound();
}
if (reader == null) {
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
} else {
// The current position in the file
position = end ? file.length() : 0;
@@ -410,22 +407,27 @@
if (reOpen) {
IOUtils.closeQuietly(reader);
}
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
if (getRun() && reOpen) {
reader = new RandomAccessFile(file, RAF_MODE);
reader.seek(position);
}
}
- } catch (Exception e) {
- listener.handle(e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ stop(e);
+ } catch (Exception e) {
+ stop(e);
} finally {
IOUtils.closeQuietly(reader);
}
}
+ private void stop(Exception e) {
+ listener.handle(e);
+ stop();
+ }
+
/**
* Allows the tailer to complete its current loop and return.
*/
{code}
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Updated] (IO-357) Tailer: InterruptedException while the
thead is sleeping is silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory updated IO-357:
----------------------------
Summary: Tailer: InterruptedException while the thead is sleeping is silently ignored (was: Tailer: Interruption while sleeping is silently ignored)
> Tailer: InterruptedException while the thead is sleeping is silently ignored
> ----------------------------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (IO-357) Tailer: Interruption while sleeping is
silently ignored
Posted by "Gary Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501689#comment-13501689 ]
Gary Gregory commented on IO-357:
---------------------------------
Hm, I like the simplicity of handing the IE at the higher level like this (and also letting a user be able to find out about the IE):
{noformat}
Index: src/main/java/org/apache/commons/io/input/Tailer.java
===================================================================
--- src/main/java/org/apache/commons/io/input/Tailer.java (revision 1411980)
+++ src/main/java/org/apache/commons/io/input/Tailer.java (working copy)
@@ -356,10 +356,7 @@
listener.fileNotFound();
}
if (reader == null) {
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
} else {
// The current position in the file
position = end ? file.length() : 0;
@@ -410,17 +407,19 @@
if (reOpen) {
IOUtils.closeQuietly(reader);
}
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- }
+ Thread.sleep(delayMillis);
if (getRun() && reOpen) {
reader = new RandomAccessFile(file, RAF_MODE);
reader.seek(position);
}
}
- } catch (Exception e) {
+ } catch (InterruptedException e) {
listener.handle(e);
+ stop();
+ Thread.currentThread().interrupt();
+ } catch (Exception e) {
+ listener.handle(e);
+ stop();
} finally {
IOUtils.closeQuietly(reader);
}
{noformat}
This based on the latest from trunk.
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Comment Edited] (IO-357) Tailer: Interruption while
sleeping is silently ignored
Posted by "Morten Hattesen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13501648#comment-13501648 ]
Morten Hattesen edited comment on IO-357 at 11/21/12 2:03 AM:
--------------------------------------------------------------
Having had another look at the code, you might also consider simply removing the two {{InterruptedException}} catch blocks, letting the surrounding catch block handle the {{InterruptException}}. That would exit the {{while}} loop, not requiring a call to {{stop()}}, and notifying the listener about the interruption:
{code}
435 } catch (Exception e) {
436 // Handles InterruptedException, too
437 listener.handle(e);
438
439 } finally {
440 IOUtils.closeQuietly(reader);
441 }
{code}
As always, the code is complete, when there is no more code to be removed ;)
was (Author: mortenh):
Having had another look at the code, you might also consider simply removing the two {{InterruptedException}} catch blocks, letting the existing catch block handle the {{InterruptException}}. That would exit the {{while}} loop, not requiring a call to {{stop()}}, and notifying the listener about the interruption:
{code}
435 } catch (Exception e) {
436 // Handles InterruptedException, too
437 listener.handle(e);
438
439 } finally {
440 IOUtils.closeQuietly(reader);
441 }
{code}
As always, the code is complete, when there is no more code to be removed ;)
> Tailer: Interruption while sleeping is silently ignored
> -------------------------------------------------------
>
> Key: IO-357
> URL: https://issues.apache.org/jira/browse/IO-357
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers
> Affects Versions: 2.4
> Reporter: Morten Hattesen
>
> The implementation of org.apache.commons.io.input.Tailer silently ignores interruptions while sleeping (in two places).
> Source snippet:
> {code}
> 360 try {
> 361 Thread.sleep(delayMillis);
> 362 } catch (InterruptedException e) {
> 363 }
> ...
> 425 try {
> 426 Thread.sleep(delayMillis);
> 427 } catch (InterruptedException e) {
> 428 }
> {code}
> This is an inappropriate behavior, since it prevents controlled shutdown by a container.
> This may be rectified in one of these ways:
> # Declare the method as "throws InterruptedException" and re-throw the InterruptedException, after possibly performing come cleanup, or removing the catch clause entirely. This will ensure that a thread interruption (possibly caused by the forced shutdown by a container) will cause processing to stop, and shutdown to proceed. Problem: Requires backwards incompatible change to method signature.
> # Treat an interrupt as an alternate way of signalling the Tailer to stop, by calling {{stop()}} in the catch clause.
> # Reassert the interrupted state of the thread by calling {{Thread.currentThread.interrupt()}} to be able to detect the interruption at a later stage.
> For reference, please refer to these resources about handling thread interruption:
> * http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html
> * Java Concurrency in Practice http://www.javaconcurrencyinpractice.com/
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira