InterruptedException and I/O?

Discussion in 'Java' started by Russell Gold, Feb 12, 2004.

  1. Russell Gold

    Russell Gold Guest

    Are there any conditions under which it is sensible that an
    InterruptedException would be thrown from
    java.net.SocketOutputStream.socketWrite? I am seeing it on Windows (JRE
    build 1.4.2_03-b02) in a case where an ObjectOutputStream attached to a
    socket is flushed within a thread. I think that the other end of the
    socket connection may be closed during the flush, but I would expect
    InterruptedIOException in that case.

    --
    Russell Gold

    http://www.httpunit.org
    Russell Gold, Feb 12, 2004
    #1
    1. Advertising

  2. Russell Gold

    Chris Smith Guest

    Russell Gold wrote:
    > Are there any conditions under which it is sensible that an
    > InterruptedException would be thrown from
    > java.net.SocketOutputStream.socketWrite? I am seeing it on Windows (JRE
    > build 1.4.2_03-b02) in a case where an ObjectOutputStream attached to a
    > socket is flushed within a thread. I think that the other end of the
    > socket connection may be closed during the flush, but I would expect
    > InterruptedIOException in that case.


    java.net.SocketOutputStream is not a public API, so there's no right
    answer regarding what can be thrown from it. I'm not aware of any
    OuputStream class that should be throwing an InterruptedException,
    though; in fact, since it's a checked exception, the compiler would
    guarantee that this wouldn't happen.

    Which public API is the exception coming from?

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Feb 13, 2004
    #2
    1. Advertising

  3. Russell Gold

    Russell Gold Guest

    In article <4.net>,
    Chris Smith <> wrote:

    > Russell Gold wrote:
    > > Are there any conditions under which it is sensible that an
    > > InterruptedException would be thrown from
    > > java.net.SocketOutputStream.socketWrite? I am seeing it on Windows (JRE
    > > build 1.4.2_03-b02) in a case where an ObjectOutputStream attached to a
    > > socket is flushed within a thread. I think that the other end of the
    > > socket connection may be closed during the flush, but I would expect
    > > InterruptedIOException in that case.

    >
    > java.net.SocketOutputStream is not a public API, so there's no right
    > answer regarding what can be thrown from it. I'm not aware of any
    > OuputStream class that should be throwing an InterruptedException,
    > though; in fact, since it's a checked exception, the compiler would
    > guarantee that this wouldn't happen.
    >
    > Which public API is the exception coming from?


    OutputOutputStream.flush, in a case when it is connected to a socket
    (see stack trace, below). This is not happening on Solaris.

    java.lang.InterruptedException
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
    at
    java.io_ObjectOutputStream$BlockDataOutputStream.flush(ObjectOutputStream
    ..java:1585)
    at java.io_ObjectOutputStream.flush(ObjectOutputStream.java:639)
    at com.x.server.rmi.RMICallHandler.run(RMICallHandler.java:182)
    at com.x.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
    at
    com.me.x.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResource
    PooledExecutor.java:192)
    04/02/10 18:21:49  at java.lang.Thread.run(Thread.java:534)

    --
    Russell Gold

    http://www.httpunit.org
    Russell Gold, Feb 13, 2004
    #3
  4. Russell Gold

    Chris Smith Guest

    Russell Gold wrote:
    > OutputOutputStream.flush, in a case when it is connected to a socket
    > (see stack trace, below). This is not happening on Solaris.


    [...]

    I'd definitely report this as a bug, if you can come up with a
    reproducible test case. It clearly shouldn't be the case. In fact,
    double wammy because you have to play tricks for the compiler to even
    let you catch the InterruptedException (i.e., it will claim that the
    code in the try block couldn't possibly throw that exception and so the
    catch block is unreachable.)

    Of course, you can work around the latter problem with:

    try
    {
    if (false) throw new InterruptedException();
    ...
    }
    catch (InterruptedException e)
    {
    ...
    }

    But that's ugly. Definitely do the bug report.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Feb 13, 2004
    #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. Daniel
    Replies:
    5
    Views:
    602
    Chris Uppal
    Dec 5, 2003
  2. Ben_
    Replies:
    2
    Views:
    12,590
    Ugo Matrangolo
    Jan 11, 2006
  3. Replies:
    1
    Views:
    737
    Andrew Thompson
    Jul 20, 2006
  4. puzzlecracker
    Replies:
    3
    Views:
    423
    Szabolcs Ferenczi
    May 12, 2008
  5. Alessio Stalla

    Re: InterruptedException handling

    Alessio Stalla, Sep 4, 2009, in forum: Java
    Replies:
    1
    Views:
    438
Loading...

Share This Page