0
Does you have to use run() and start() when using threads?
"As you can see, our Loader class extends the Thread class and overrides its run() method. When we create the obj object and call its start() method, the run() method statements execute on a different thread." I mean since the first question for threads you have to write run and start to get the right answer... Is it just as a norm you should follow, but other words would be valid aswell and the code would run just fine?
1 ответ
0
I can't relate to the context in the beginning, because I don't remember this part of a task, though I can answer you on your thread question. In general there are two options to create a thread.
Option 1: Extend the Thread class and override the run method for your personal use
Option 2: Make a Runnable Class and give a runnable object as the argument for a thread constructor
For both options the proper way to start this thread is to call the start method of the thread object. This will register the thread in the event queue and grant the thread the privilege to work apart the main thread