Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse(Java)中的控制台没有按正确的/时间顺序输出内容_Java_Eclipse_Console - Fatal编程技术网

Eclipse(Java)中的控制台没有按正确的/时间顺序输出内容

Eclipse(Java)中的控制台没有按正确的/时间顺序输出内容,java,eclipse,console,Java,Eclipse,Console,为什么以下测试代码的输出顺序不正确: public static void main(String[] args) { boolean test = false; try { assert test: "will fail with -ea enabled in VM args" ; } catch (AssertionError e) { e.printStackTrace(); System.out.println(

为什么以下测试代码的输出顺序不正确:

public static void main(String[] args) {

    boolean test = false;

    try {
        assert test: "will fail with -ea enabled in VM args" ;
    } catch (AssertionError e) {
        e.printStackTrace();
        System.out.println("idk why you would use this but...");
    }

    System.out.println(test + " sneaks in between");

}
在VM参数中启用“-ea”的情况下运行此命令(运行配置)

随机输出为:

java.lang.AssertionError: will fail with -ea enabled in VM args
    at Main.main(Main.java:31)
FOO
BAR
(应该发生)或:

(不应该发生)有时:

java.lang.AssertionError: ERROR
FOO
    at Main.main(Main.java:31)
BAR
这件事发生时,我正在胡闹“断言”。我知道这段代码完全是胡说八道,但它也可能发生在其他设置中。 在许多程序中,Seconldy控制台并没有作为正式的东西被过多地使用,主要用于调试。但这仍然很奇怪

这是因为try-catch正在另一个线程上运行吗?或者这些事情发生的太快了,以至于一件事比另一件事先推出来

我注意到添加了一个线程;(需要扔掉或抓住的) 它总是按时间顺序排列,所以


为什么不按时间顺序打印代码?

printStackTrace()
打印到错误中。如何按时间顺序与标准排成一行是不确定的。您可以尝试在
System.out
上调用
flush()
,但我不能向您保证结果会与您期望的一样,除非您使用其他可用方法之一将堆栈跟踪打印到标准输出。

是的,当使用e.printStackTrace(System.out)指定打印流时,我得到了正确的结果;(除了文本不是红色)我猜:然后也回答它,(编辑)注意,我不知道printStackTrace()使用的是System.err输出流,我甚至没有想到这一点。
java.lang.AssertionError: ERROR
FOO
    at Main.main(Main.java:31)
BAR