System.out实现在输出流中包含一个同步块.
/**
* Prints a String and then terminate the line. This method behaves as
* though it invokes {@link #print(String)}
and then
* {@link #println()}
.
*
* @param x The String
to be printed.
*/
public void println(String x) {
synchronized (this) {
print(x);
newLine();
}
}
放置System.out.println很多将使整个项目运行几乎单线程,因为所有线程将等待同步锁定,并使您的应用程序开始爬行.
这意味着你的上司是对的.
或者,使用像log4j这样的日志框架.您仍然可以将log4j配置为依次输出到System.out.println,只需在appender配置中进行微小更改即可.