I have a strange problem and it would be nice if I could solve it. For the debugging purposes (and some other things, as well) I'm writing a log of a console Java application on the standard output. Some things that are writen on standard out, and some things like errors are printed on standard error. The problem is that these two are not perfectly synchronized, so the order of printed lines is not always correct. I guess this is because many things are printed and it happens that a buffer for one output is full so the other output prints before the first one flushes it buffer.
E.g., I want to write this:
syso: aaa
syso: bbb
syso: ccc
syso: ddd
syso: eee
syserr: ---
What is sometimes printed is
aaa
bbb
ccc
---
ddd
eee
Sometimes there is not a new line in between, so it looks like
aaa
bbb
ccc---
ddd
eee
Every time I print something on an output, I flush the same output with
System.out.flush();
or
System.err.flush();
How to solve this problem?
Btw, everything is printed in the Eclipse console.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…