Java: why Thread.sleep() and yield() are static?

后端 未结 6 379
庸人自扰
庸人自扰 2021-01-03 19:56

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

6条回答
  •  半阙折子戏
    2021-01-03 20:42

    The same reason is why stop() and suspend() methods are deprecated. Intrusion in thread's state from outside is dangerous and can cause unpredictable result. And if sleep is not static, for example, how do you think interruption from it will happen?

提交回复
热议问题