为什么我们调用Thread.start()方法反过来调用run方法? [英] Why we call Thread.start() method which in turns calls run method?

查看:292
本文介绍了为什么我们调用Thread.start()方法反过来调用run方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们调用线程对象的 start()方法然后调用 run()方法,为什么不是我们直接调用 run()方法?

Why do we call the thread object's start() method which in turns calls run() method, why not we directly call run() method?

推荐答案


[...]为什么我们不直接调用run()方法?

[...] why not we directly call run() method?

run()方法只是一种普通的方法(由覆盖)。与任何其他普通方法一样,直接调用它将导致当前线程执行 run()

The run() method is just an ordinary method (overridden by you). As with any other ordinary method and calling it directly will cause the current thread to execute run().

所有魔法都发生在 start()中。 start()方法将导致JVM生成新线程并使新生成的线程执行 run()

All magic happens inside start(). The start() method will cause the JVM to spawn a new thread and make the newly spawned thread execute run().

这篇关于为什么我们调用Thread.start()方法反过来调用run方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆