But why should you implement an interface for java for a stream?
You do not have, as you said earlier, you can extend the Thread object and implement the public void run method. If you want a more organized and flexible (yes, flexible) approach, you definitely want to use Runnable for the obvious reason: code reuse.
When I talk about organized, I want to say that itβs easy to maintain
Runnable doSomething = new Runnable() { @Override public void run() { goAndDoSomethingReallyHeavyWork(); } };
and then reuse the same runnable for another thread or the same thread at another moment (yes, you can actually use Thread) than to extend 2 or more threads into objects that you will use once.
What are the values ββof the runnable interface that does work with java thread?
The important thing is that the Thread object will βknowβ that your Runnable starts the method and executes it when it has to (and so stop, pause, and other Thread actions).
Is there a Java interface from something?
This question is worth my +1 to you. I would really like to know, but it seems that this is a feature of the language, not a product of itself, like any other object that extends the superclass of the Object class.
Hope this helps. Greetings
source share