System.out vs System.err

Seoyeon Kim·2023년 3월 21일
0

out

public static final PrintStream out
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
For simple stand-alone Java applications, a typical way to write a line of output data is:

 System.out.println(data)

See the println methods in class PrintStream.

err

public static final PrintStream err
The "standard" error output stream. This stream is already open and ready to accept output data.
Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out, has been redirected to a file or other destination that is typically not continuously monitored.


outerr 는 서로 다른 타이밍에 flush한다.

print 구문이 있을 때마다 flush 하는 것이 JVM의 성능에 영향을 주기 때문에 out은 여러 개의 print request를 buffer에 넣고 기다렸다가 한 번에 출력한다.

반면에 err는 일반적이지 않은 상황에서의 출력을 의미하기 때문에 buffer를 갖고 있긴 하지만 대부분 곧바로 flush 한다.

0개의 댓글