且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java中新创建的线程的执行顺序是什么

更新时间:2023-02-01 08:25:30

线程启动的顺序取决于操作系统,Java语言规范中未指定.您在主线程中调用start,但是当新线程被分配并开始处理时,其Runnable或run方法将留给操作系统的调度程序来决定.

The order in which threads start is up to the OS, it is not specified in the Java Language Spec. You call start in the main thread, but when the new thread gets allocated and when it begins processing its Runnable or run method is left to the OS' scheduler to decide.

请注意不要依赖于线程启动的顺序.

Be careful not to rely on the order in which threads happen to start.