Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #11069 > unrolled thread
| Started by | Jan Burse <janburse@fastmail.fm> |
|---|---|
| First post | 2012-01-04 18:59 +0100 |
| Last post | 2012-01-08 14:12 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
BufferedWriter cannot handle InterruptedIOException Jan Burse <janburse@fastmail.fm> - 2012-01-04 18:59 +0100
Corr: BufferedOutputStream cannot handle InterruptedIOException Jan Burse <janburse@fastmail.fm> - 2012-01-04 19:00 +0100
Re: BufferedWriter cannot handle InterruptedIOException Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-01-04 13:41 -0800
Re: BufferedWriter cannot handle InterruptedIOException Tom Anderson <twic@urchin.earth.li> - 2012-01-08 14:12 +0000
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2012-01-04 18:59 +0100 |
| Subject | BufferedWriter cannot handle InterruptedIOException |
| Message-ID | <je241r$pon$1@news.albasani.net> |
Dear All,
Just reading the spec of InterruptedIOException:
"Signals that an I/O operation has been
interrupted. An <code>InterruptedIOException</code>
is thrown to indicate that an input or output
transfer has been terminated because the thread
performing it was interrupted. The field {@link
#bytesTransferred} indicates how many bytes were
successfully transferred before the interruption
occurred."
But I think this does not carry over to BufferedOutputStream. I
find the following code there:
/** Flush the internal buffer */
private void flushBuffer() throws IOException {
if (count > 0) {
out.write(buf, 0, count);
count = 0;
}
}
In case that out throws an InterruptedIOException exception,
the write operation is directly terminated, and the count
is not set to zero.
As an effect next time flushBuffer is called again, the
same bytes are written out again.
Some better BufferedOutputStream class known?
Bye
[toc] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2012-01-04 19:00 +0100 |
| Subject | Corr: BufferedOutputStream cannot handle InterruptedIOException |
| Message-ID | <je243j$pon$3@news.albasani.net> |
| In reply to | #11069 |
Oops, title of post corrected.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2012-01-04 13:41 -0800 |
| Message-ID | <4I3Nq.48143$mJ.28918@newsfe10.iad> |
| In reply to | #11069 |
On 1/4/12 9:59 AM, Jan Burse wrote:
> Dear All,
>
> Just reading the spec of InterruptedIOException:
>
> "Signals that an I/O operation has been
> interrupted. An <code>InterruptedIOException</code>
> is thrown to indicate that an input or output
> transfer has been terminated because the thread
> performing it was interrupted. The field {@link
> #bytesTransferred} indicates how many bytes were
> successfully transferred before the interruption
> occurred."
>
> But I think this does not carry over to BufferedOutputStream. I
> find the following code there:
>
> /** Flush the internal buffer */
> private void flushBuffer() throws IOException {
> if (count > 0) {
> out.write(buf, 0, count);
> count = 0;
> }
> }
>
> In case that out throws an InterruptedIOException exception,
> the write operation is directly terminated, and the count
> is not set to zero.
>
> As an effect next time flushBuffer is called again, the
> same bytes are written out again.
>
> Some better BufferedOutputStream class known?
>
> Bye
Interestingly enough, I don't see any implementation of OutputStream in
the standard JDK which actually set that bytesTransferred field, so it
is always 0.
Often when a thread is interrupted, it is an indication that the
operation it is doing should be aborted. It was probably a mistake to
include the "bytesTransferred" field in the API, or perhaps it was
intended for read operations.
Hope this helps,
Daniel.
[toc] | [prev] | [next] | [standalone]
| From | Tom Anderson <twic@urchin.earth.li> |
|---|---|
| Date | 2012-01-08 14:12 +0000 |
| Message-ID | <alpine.DEB.2.00.1201081409510.20221@urchin.earth.li> |
| In reply to | #11069 |
On Wed, 4 Jan 2012, Jan Burse wrote:
> But I think this does not carry over to BufferedOutputStream. I
> find the following code there:
>
> /** Flush the internal buffer */
> private void flushBuffer() throws IOException {
> if (count > 0) {
> out.write(buf, 0, count);
> count = 0;
> }
> }
>
> In case that out throws an InterruptedIOException exception,
> the write operation is directly terminated, and the count
> is not set to zero.
>
> As an effect next time flushBuffer is called again, the
> same bytes are written out again.
What should happen? The field should be set to zero? That means that if
the interruption occurred *before* the bytes got written out, then they
will be lost forever.
The problem with InterruptedIOException, like any IOException, is that
there is no way to know what point in the IO operation it occurred.
Really, at that point, the only safe thing to do is to close the stream
and start again from scratch.
tom
--
music is a interesting thing, DUN COMPARE AND PUT IT TO BLAR BLAR GENRE,
THIS IS A STUPID ACT......MUSIC IS SAME TO EVERYONE -- sihamze
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web