java - 线程的 start() 能保证顺序吗?
PHP中文网
PHP中文网 2017-04-18 10:34:58
0
4
445

在 main 中创建两个线程,先 thread1.start();然后 thread2.start();能确保 thread1 的 run() 方法先执行吗?

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
大家讲道理

No, after the start method is called, the thread only becomes the ready state, not the running state - then the JVM arranges when the thread runs (that is, executes the run method of Thread)

伊谢尔伦
  • Of course not

  • However, directly executing the run method can cause the code in run() to be executed serially in the current thread

Ty80

Since thread concurrency is used, the key issue to consider is not the order of execution. If you have to do it on a first-come, first-served basis, then use the join method

PHPzhong

Can you find the answer yourself before asking the question? There is enough information online about the basic concepts of threads.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!