Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java thread which is better way?

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?

like image 345
Venkat Avatar asked Mar 11 '10 14:03

Venkat


People also ask

Which method is best in thread?

The answer to this one is simple — never override Thread if the only thing you intend to change is the run() method.

What are ways to create thread & Which is the best way?

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.

What are threads good for in Java?

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.


1 Answers

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.

like image 171
Riduidel Avatar answered Oct 18 '22 01:10

Riduidel