java - Any issues with replacing new Socket() with SocketChannel.open().socket()? -
what can go wrong if replace
socket = new socket()
with
socket = socketchannel.open().socket()?
background: have legacy code using new socket()
, , wanted able interrupt socket.connect()
call. don't want rewrite code use nio. learned thread.interrupt()
not interrupt socket.connect()
, socket.close()
on thread supposed interrupt connection. oddly, worked java 7 not java 6.
i somehow got head using socket = socketchannel().open().socket()
magically allow me use thread.interrupt()
interrupt socket.connect()
. doesn't, oddly, make socket.close()
interrupt socket.connect()
in java 6 too!
note i'm not directly using attached socketchannel
in way---it appears when create socket
, never again.
what can go wrong this?
there several.
- a socket acquired via socketchannel doesn't appear support read timeouts.
- the inputstream , outputstream of socket aren't independent: have mutual lock in common.
why want interrupt connect() call? surely want connect timeout?
Comments
Post a Comment