Threads java help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

4th Nov 2017, 4:11 PM
oyl
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.
4th Nov 2017, 6:49 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
start() Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
4th Nov 2017, 6:10 PM
D_Stark
D_Stark - avatar
+ 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.
5th Nov 2017, 4:14 AM
Talluri Saisumanth
Talluri Saisumanth - avatar
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?
4th Nov 2017, 6:32 PM
oyl