while creating a thread in java, there is two ways such as Extending threads and Implement runnable Interface. I am unaware of Which is the better way of creating threads?
The answer to this one is simple — never override Thread if the only thing you intend to change is the run() method.
You can create threads by implementing the runnable interface and overriding the run() method. Then, you can create a thread object and call the start() method. Thread Class: The Thread class provides constructors and methods for creating and operating on threads.
Threads allows a program to operate more efficiently by doing multiple things at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program.
Obvously, implementing Runnable is by far better since it potentially allow you to use thread pools and execution queue that you couldn't use with Thread, besides the obvious fact your thread number is limited in the JVM.
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