Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>if(s.isClosed() || !s.isConnected() || s.isInputShutdown() || s.isOutputShutdown() || out == null || out.checkError()) </code></pre> <p>This is a series of mostly futile tests.</p> <ul> <li>if the socket is closed you shouldn't be in this part of the code at all.</li> <li>if the socket isn't connected, ditto.</li> <li>if you have shutdown the socket for input it doesn't mean you can't write.</li> <li>if you have shutdown the socket for output you shouldn't be in this part of the code.</li> <li>if <code>out</code> is null you shouldn't be in this part of the code.</li> <li>Testing <code>checkError()</code> is good, but you shouldn't really be using <code>PrintWriter</code> over a network at all, because it swallows exceptions. It would be better to use <code>BufferedWriter</code> and let the exceptions tell you about things going wrong as they happen, rather than on the next write as you are doing here.</li> </ul> <p>You also need to understand that <code>Socket.isClosed()</code> only tells you whether <em>you</em> have closed the <code>Socket.</code> Similarly, <code>Socket.isConnected()</code> only tells you that you have connected the <code>Socket,</code> or received it already connected via a constructor, or <code>ServerSocket.accept()</code>. Same goes for <code>isInputShutdown()</code> and <code>isOutputShutdown().</code> They only tell you what you have done to the <code>Socket.</code> None of these methods tells you anything about the state of the <em>connection</em>. </p> <blockquote> <p>This thread dump info points out that the problem lies in Printwriter.checkError(). But i can't understand why it would stop here.</p> </blockquote> <p>Because, as the stack trace also tells you, it is calling <code>flush().</code> If that blocks it means you have overrun the reader, and TCP is waiting for him to read some data to free buffer space in his socket receive buffer and therefore your socket send buffer. Until that happens, the underlying <code>send()</code> will block. Nothing you can do about that, except speed up the reader.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload