【问题标题】:Why is System.err slower than System.out in Eclipse? [duplicate]为什么 System.err 在 Eclipse 中比 System.out 慢? [复制]
【发布时间】:2012-11-19 08:24:41
【问题描述】:

可能重复:
Java: System.out.println and System.err.println out of order

为什么是这个代码

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

打印

out
err

在 Eclipse 控制台上?

更新

如果我从命令行运行,相同的代码会以正确的顺序打印。

更新

如果我修复它

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

它在 Eclipse 中也能正确打印

【问题讨论】:

    标签: java eclipse stderr stdio


    【解决方案1】:

    并不慢;他们只是不一定是flushed。但是,您可以解决这个问题:

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

    好的,这似乎是一个已知的 Eclipse 错误:https://bugs.eclipse.org/bugs/show_bug.cgi?id=32205

    【讨论】:

    • 但是 println 也调用了 flush()。请参阅 PrintStream.println。
    • 我不相信您的(阅读:Eclipse 的)println() 实现确实调用了flush()
    • 确实如此。我调试了它,它涉及到 java.io.PrintStream.newLine() 它调用了flush()。
    • 查看我的编辑。显然这只是一个长期存在的 Eclipse 错误。
    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2020-01-20
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    相关资源
    最近更新 更多