Why sleep()
and yield()
methods are defined as static
methods in java.lang.Thread
class
?
Advertisement
Answer
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.