Why is System.err slower than System.out in Eclips

2019-02-24 06:49发布

问题:

Possible Duplicate:
Java: System.out.println and System.err.println out of order

Why this code

    System.err.println("err");
    System.out.println("out");

prints

out
err

on Eclipse console?

UPDATE

The same code prints in correct order if I run it from command line.

UPDATE

If I fix it as

    System.err.println("err");
    Thread.sleep(5);
    System.out.println("out");

It prints correctly in Eclipse too

回答1:

It's not slower; they're just not necessarily flushed in order. You can fix that, however:

System.err.println("err");
System.err.flush();
System.out.println("out");

Okay, so this appears to be a known Eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=32205