System.out和System.error一起用的问题
- 问题出现
竟然不按代码顺序出牌!!!!
原因是因为System.out和System.error一起用导致
System.err.println("this is printSomeThing Core ServiceImpl");
System.out.println("TagService代理前");
Object returnObject = method.invoke(this.object, args);
System.out.println("TagService代理后");
- 总结
- System.out在JVM和操作系统都具有缓存功能,输出的东西不一定实时输出,可能积累几个字符才会一块输出
- System.err 不带缓存(默认,可修改),会实时输出,打印的东西可以立马显示在屏幕
- 如果使用了log4j的日志记录,System.err会被记入日志,System.out不会
所以在我们测试的时候 ,不要混用,不然会怀疑人生