0
Threads java help
can someone explain how does this thread code work?i cant understand the explanation in the sololearn lesson. https://code.sololearn.com/ci0n6OJsL2os/?ref=app
4 Answers
+ 9
Since Loader class is extending Thread class, it'll inherit all properties of Thread class and will behave like a Thread.
When we call start() method for a Thread object, it'll create a new thread and automatically call the run() method for the newly created object.
run() : the existing thread runs š
start() : a new thread is born š¶ and it runs š
So if you directly call the run() method without calling the start() method, it WON'T create a new thread, it'll just call run() for the CURRENT thread.
+ 3
start()
Causes this thread to begin execution; the Java Virtual Machine calls theĀ runĀ method of this thread.
+ 1
aĀ threadĀ is a program's path of execution. Most programs written today run as a single thread, causing problems when multiple events or actions need to occur at the same time.Ā
The ideal solution to this problem is the seamless execution of two or more sections of a program at the same time. Threads allows us to do this.
0
so when a class extends thread,this class becomes a new thread?so in the order for this new thread to execute run(),start() must be called?