当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Synchronize System.out & System.err

问题描述:

This question already has an answer here:

  • Java: System.out.println and System.err.println out of order

    5 answers

网友答案:

You can avoid this issue by calling flush each time you write to either stream. e.g.:

System.out.println ("Writing to *out*");
System.out.flush ();

If you are logging from different threads, then your logging messages will naturally interleave. If you want to cleanly separate the output by threads, I'd suggest using a logging library such as log4j.

分享给朋友:
您可能感兴趣的文章:
随机阅读: