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

后端 未结 6 386
庸人自扰
庸人自扰 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:39

    This is because whenever you are calling these methods, those are applied on the same thread that is running. You can't tell another thread to perform some operation like, sleep() or wait. All the operation are performed on the thread which is being executed currently.

提交回复
热议问题