This question already has an answer here:
Java: System.out.println and System.err.println out of order
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.