Java:为什么Thread.sleep()和yield()是静态的? [英] Java: why Thread.sleep() and yield() are static?

查看:312
本文介绍了Java:为什么Thread.sleep()和yield()是静态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 sleep() yield()方法被定义为 static 中的方法java.lang.Thread class

Why sleep() and yield() methods are defined as static methods in java.lang.Thread class?

推荐答案

代码只会在执行 someXThread 时执行,在这种情况下告诉 someYThread 屈服将毫无意义。因为唯一值得调用 yield on的线程是当前线程,所以它们使方法 static 所以你不会试图在 yield =noreferrer>其他一些主题

The code would only execute when someXThread was executing, in which case telling someYThread to yield would be pointless. So since the only thread worth calling yield on is the current thread, they make the method static so you won't waste time trying to call yield on some other thread.

这篇关于Java:为什么Thread.sleep()和yield()是静态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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