一个通信程序,我的一个类用NIO从网关处得到数据然后是对数据进行组合处理,处理完后在通过一个String得全局变量传给另一个类,该类把这个字符串通过NIO写进NIO得Channel,再者客户端通过NIO从Channel中得到该字符串变量。可是这样运行后8分钟左右就出现延时了。
如果我不把该字符串变量写给客户端的话,就不出现延时~~~~~~~~~~~~~~~
这是怎么回事~~~~~~~~~~~~public void writeToChannel( SocketChannel channel, String message ) throws IOException {
// System.out.println("写");
int x=channel.socket().getSendBufferSize();
ByteBuffer buf =ByteBuffer.allocateDirect(x);
buf=ByteBuffer.wrap( message.getBytes() );
// ByteBuffer buf=ByteBuffer.wrap(message.getBytes());
// int nbytes = channel.write( buf );
channel.write( buf );
buf.clear();
channel.close();
}
具体是通过这个方法写进Channel的,看有什么不妥吗???