If you call start() method on Thread, Java Virtual Machine will call run() method and two threads will run concurrently now - Current Thread and Other Thread or Runnable implementation.
The run method is just another method. If you call it directly, then it will execute not in another thread, but in the current thread. If start isn't called, then the Thread created will never run. The main thread will finish and the Thread will be garbage collected.
Instead the run() method is executed by the thread that created the thread. In other words, the thread that executed the above two lines of code. To have the run() method of the MyRunnable instance called by the new created thread, newThread , you MUST call the newThread. start() method.
When a Thread object's run() method is invoked directly, the statements in the run() method are executed by the current thread rather than by the newly created thread.
t1=threading.Thread(target=self.read()) print("something") t2=threading.Thread(target=self.runChecks(), args=(self,))
self.read
runs indefinitely, so the program won't ever reach the print
line. How is this possible without calling t1.start()
? (Even if I call that, it shold start running and go on to the next line, shouldn't it?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With