Stack trace is not printed in proper order with other messages on console

后端 未结 1 986
刺人心
刺人心 2020-12-19 11:32

Why does it happen that the stack trace printed for the following Java program is not displayed in a proper order on the console screen? It gets mi

相关标签:
1条回答
  • 2020-12-19 12:12

    This has to do more with the implementation of the standard output and error streams than Eclipse.

    Both System.out and System.err are PrintStream objects which may be passed buffered streams that do not automatically flush data to their destinations. Since they are two different streams with buffering used internally, the data you write to them may be interleaved because the streams may decide to flush at different times (the buffer contents may be filled at different times).

    Calling System.err.flush() after printing the first two stack traces and then System.out.flush() after printing to the std output stream should get consistent results.

    0 讨论(0)
提交回复
热议问题