でこの例外が発生する理由を誰か教えてくださいsc.connect
( sc = ソケットチャネル)
/**
* Verify socket is connected. If not currently connected will attempt to connect
* @return true if already connected or connection successfully established
*/
private synchronized boolean verifyConnection() {
if (sc.isConnected()) {
return true;
}
try {
if (!sc.isOpen()) {
logger.info("Channel WebBroker->CC is CLOSED unexpectedly. Opening new channel " + getIpAddress() + ":" + getIpPort() + "");
openChannel();
}
sc.socket().close();
sc.connect(new InetSocketAddress(getIpAddress(), getIpPort()));
while(!sc.finishConnect()){
Thread.sleep(1);
}
logger.info("Connection established " + getIpAddress() + ":" + getIpPort());
sc.socket().setKeepAlive(true);
return sc.isConnected();
} catch (Exception e) {
logger.info("failed to connect to " + getIpAddress() + ":" + getIpPort(), e);
return false;
}
}
private void openChannel() throws Exception {
sc = SocketChannel.open();
sc.socket().setKeepAlive(true);
sc.socket().setSoTimeout(30000);
}
[エラー] 10.201.1.53:8084 に接続できませんでした
java.nio.channels.ClosedChannelException: null
at sun.nio.ch.SocketChannelImpl.ensureOpenAndUnconnected(SocketChannelImpl.java:472) ~[na:1.6.0_07]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:486) ~[na:1.6.0_07]
編集:最後に、これは以下の行が原因であることがわかりました。
sc.socket().close();