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?