首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

IO通信模型(二)同步非阻塞模式NIO(NonBlocking IO)

在发起 accpet()和 read()请求之后会持续阻塞,但是Java中提供了 setSoTimeout()方法设置超时时间,在固定时间内没有得到结果,就会结束本次阻塞,等待进行下一次的阻塞轮训。...Java中Socket中的 setSoTimeout()方法: public synchronized void setSoTimeout(int timeout) throws SocketException...negative"); getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); } Java同步非阻塞模式编码 通过设置 setSoTimeout...) throws Exception { ServerSocket serverSocket = new ServerSocket(83); serverSocket.setSoTimeout...new StringBuffer(); //下面我们收取信息(设置成非阻塞方式,这样read信息的时候,又可以做一些其他事情) this.socket.setSoTimeout

82610
您找到你想要的搜索结果了吗?
是的
没有找到
领券