问题描述:

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.

相关阅读:
Top