Recommended way to handle ClosedByInterruptException?

Discussion in 'Java' started by raphfrk@gmail.com, Jan 3, 2013.

  1. Guest

    This is an example of what causes this exception

    http://hastebin.com/mayuyuvimu.avrasm

    This gives:

    Exception in thread "main" java.nio.channels.ClosedByInterruptException
    at java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)
    at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:880)
    at Main.main(Main.java:17)

    ----------------------

    Anyway, there doesn't seem to be any sane way of dealing with this. If interrupt is intended to mean stop what you are doing and stop the thread cleanly, then this works against that. This prevents you doing any more writesto the file. Is the intention that you reopen the file and then do the writes.

    Also, it doesn't even clear the interrupted flag. So, you have to wipe theflag manually if you want to repeat the write attempt.
    , Jan 3, 2013
    #1
    1. Advertising

  2. On 1/2/2013 6:43 PM, wrote:
    > This is an example of what causes this exception
    >
    > http://hastebin.com/mayuyuvimu.avrasm
    >
    > This gives:
    >
    > Exception in thread "main"
    > java.nio.channels.ClosedByInterruptException at
    > java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)
    >
    >

    at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:880)
    > at Main.main(Main.java:17)
    >
    > ----------------------
    >
    > Anyway, there doesn't seem to be any sane way of dealing with this.
    > If interrupt is intended to mean stop what you are doing and stop the
    > thread cleanly, then this works against that. This prevents you
    > doing any more writes to the file. Is the intention that you reopen
    > the file and then do the writes.
    >
    > Also, it doesn't even clear the interrupted flag. So, you have to
    > wipe the flag manually if you want to repeat the write attempt.
    >


    I think the intent is that interrupting a blocked file channel is an
    immediate abort, not a way to stop the thread cleanly. From the docs on
    ClosedByInterruptException; "Checked exception received by a thread
    when another thread interrupts it while it is blocked in an I/O
    operation upon a channel. Before this exception is thrown the channel
    will have been closed and the interrupt status of the previously-blocked
    thread will have been set."

    Are you deliberately interrupting the thread or is something
    unanticipated happening?

    --

    Knute Johnson
    Knute Johnson, Jan 3, 2013
    #2
    1. Advertising

  3. Guest

    The idea is to have a thread that handles the actual writing to disk.

    On shutdown, the thread is interrupted. It then writes any remaining data and then the thread dies.

    However, with this, if the a .map() call is made after the interrupt, the files closes.
    , Jan 3, 2013
    #3
  4. On 1/3/2013 1:12 PM, wrote:
    > The idea is to have a thread that handles the actual writing to
    > disk.
    >
    > On shutdown, the thread is interrupted. It then writes any remaining
    > data and then the thread dies.
    >
    > However, with this, if the a .map() call is made after the interrupt,
    > the files closes.
    >


    I think the answer is self evident then, don't interrupt it.

    --

    Knute Johnson
    Knute Johnson, Jan 3, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rico Alexander
    Replies:
    3
    Views:
    328
    William Ryan
    Oct 17, 2003
  2. Al Koch
    Replies:
    0
    Views:
    355
    Al Koch
    Jun 25, 2005
  3. Michele Simionato

    recommended way of generating HTML from Python

    Michele Simionato, Feb 20, 2005, in forum: Python
    Replies:
    13
    Views:
    584
    paul koelle
    Feb 22, 2005
  4. Russell Warren
    Replies:
    0
    Views:
    251
    Russell Warren
    Jun 19, 2006
  5. Paul
    Replies:
    1
    Views:
    382
Loading...

Share This Page