I know there are quite a few ways of creating a thread in java. I have used the "Extending Thread Class" method and checked out various methods like getName(), sleep(), etc.
However, how can i use these methods if I am creating a thread by implementing the Runnable interface. And, so if i dont extends Thread class, I get symbol not found error for methods like sleep. Could anyone suggest how to go about doing this?
You might notice that Runnable is in no way related to Threads, however, Threads are related to Runnable (see the java.lang.Thread class for its dependency).
A Runnable is the closest thing to what other languages call a "closure" - or if you are familiar with .NET, a "delegate". Simply, it is a piece of executable code that can be passed around for execution. Sometimes it is often called a "callback", however, this implies more context than is required to talk about it in this context.
A Runnable simply allows you to pass "some piece of code" for some arbitrary thread to execute it. That it does so by "calling back on the run method" is irrelevant to the more abstract definition of how and why things work. However, what is of importance is that you have separated "the piece of code to execute" and "the thread(s) that will execute it".