Closes a socket from a separate thread thread-safe when using old-style I / O? If not, what are the alternatives?
Yes.
An alternative is to use NIO lock (which is the default behavior for SocketChannel BTW). I prefer this for a small number of compounds since it has NIO efficiency, but some of the simplicity of Plain IO.
Closes a socket / channel from a separate stream thread-safe when using NIO instead?
For NIO locks and without NIO locks, they are thread safe.
Is there a difference in the behavior of Socket.close () when using NIO as opposed to regular IO?
If you need to know the details, I suggest you read the code, but basically they are the same.
Are there any advantages to using NIO for networking, other than the ability to shut down blocked I / O by simply interrupting the flow (so that I no longer need to refer to the socket)?
As you close the connection, this is the least problem. So yes, there are many reasons to consider NIO compared to regular IO.
Pros for NIO
- Faster and lighter weight when using direct memory
- More scalable to tens of thousands of users.
- Supports effective expectation of expectation.
vs
- Normal IO is easier to code.
- For this reason, many APIs support only simple IO.
source share