1) Is the possible? What are the implications?
Yes it is possible.
The implication is that any state in the Runnable is (potentially) shared by all threads, and access to / update of that state needs to be properly synchronized.
2) If I call Thread.sleep(0); in class MyRunnable, will both threads sleep because they are the same object, or is the thread entity completely separate from the object?
No, they won't.
The Thread is logically distinct from the Runnable
. Calling Thread.sleep()
doesn't directly effect the Runnable
and other threads that may be sharing it. (It could effect other threads indirectly; e.g. if one thread sleeps while it is holding the Runnable's primitive lock, and the other threads need to acquire the lock to make progress.)
3) Would there ever be a reason to do this, if not please still answer the two questions above, because I don't think I fully understand the thread mechanism yet?
You might do this if there is no thread-specific state associated with the Runnable
and you wanted to minimize space overheads, or the overheads of initializing the Runnable
. But such use-cases are rare in practice.
In the vast majority of real-world use-cases each thread needs a distinct Runnable
instance.