I
I
Ilya Slobodanyuk2017-08-15 16:38:09
Java
Ilya Slobodanyuk, 2017-08-15 16:38:09

What is the difference between the run method from Thread and the same method from Runnable?

Help me understand the difference between the run method from the Thread class and the same method from the Runnable interface, do they even exist?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-08-15
@sergey-gornostaev

I'll tell you something terrible now: Thread is Runnable . So no difference.

A
AngeuT, 2017-08-15
@AngeuT

Runnable- task interface with method run().
Thread- task executor in a new thread.
It Threadalso implements the interface Runnableand launches its own task defined in its method run()in a new thread; by default, its task is to launch another task passed to it, for example, through the constructor new Thread(Runnable).
The method run()on the Thread object is never called on its own, since the essence of the Thread object is to create a new thread, and then the jvm itself will start executing the task by calling the method run()in the new thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question