有以下代码:      

 BufferedReader localReader = new BufferedReader(new InputStreamReader(System.in));
String msg=null;
System.out.println("out of while loop!");
while((msg=localReader.readLine())!=null){
System.out.println(msg)
if(msg.equals("bye")){
break;
} }

  本来以为localReader.readLine()读取不到数据时会返回null,结果执行代码后不输入数据时一直停留在while循环体内等待,故readLine()方法是一个阻塞函数。Java API文档如下描述:

public String readLine()throws IOException
  Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

  表示该方法读取一行文本,当遇到换行符"\n",回车符"\r"或者回车符后面紧跟着换行符时,该行结束并返回。没有数据时,将会一直处于等待状态。因此在进行网络连接时,应该避免使用该方法。

最新文章

  1. 学习3ds max插件开发过程中的一些小结
  2. JFinal - scheduler 插件做定时任务
  3. JavaScript校验图片格式及大小
  4. 华硕电脑安装ubuntu出现问题及决方案
  5. My集合框架第二弹 二叉树的实现
  6. 重置mysql管理员密码
  7. phpStorm 快捷键收集以及配色方案
  8. C语言生产随机数的方法
  9. PowerShell 管道和对象成员
  10. Android的BUG(二) - SurfaceTexture中的野指针
  11. HDU 5933/思维
  12. mysql新建数据库时的collation选择(转)
  13. JavaScript高级内容:原型链、继承、执行上下文、作用域链、闭包
  14. Oracle 每天自动生成AWR报告
  15. 2017年国内常用的公共NTP服务
  16. 数据结构与算法(十):红黑树与TreeMap详细解析
  17. web进修之—Hibernate起步(1)(2)
  18. java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context 错误
  19. centos7如何查询已运行服务?
  20. Beta冲刺——第一天

热门文章

  1. 安装 neo4j 在 .../bin 目录下使用 ./neo4j 没反应 和 从csv 导入数据到neo4j
  2. Oracle VM VirtualBox做好虚拟硬盘后,如何进一步修改虚拟硬盘的大小
  3. js中定时器之一
  4. 1、JDK自带注解
  5. dubbo-admin 管理平台
  6. scrollLeft滚动(用animate替代)
  7. IE8兼容background-size
  8. Educational Codeforces Round 59
  9. [leetcode]438. Find All Anagrams in a String找出所有变位词
  10. Spring集成Redis使用注解