Thread class and Runnable interface in Java

Difference between Thread class and Runnable interface in java-

  1. Mul­ti­ple Inher­i­tance– The lim­i­ta­tion with“extends Thread” approach is that if you stretch Thread, you can­not stretch any­thing else. Java doesn’t sup­port mul­ti­ple inher­i­tance. In real­i­ty, you don’t need Thread class behav­iour, because to be able to use a thread you will need to instan­ti­ate one any­way.
    On the oth­er hand,
    Imple­ment­ing the Runnable inter­face gives you the choice to expand any class you want, but nev­er­the­less spec­i­fy behav­ior which will be con­duct­ed by var­i­ous thread.
  2. Reusabil­i­ty– In“implements Runnable”, we’re devel­op­ing a dis­tinct Runnable course for a par­tic­u­lar con­duct job (if the job that you would like to get per­formed is project ). It pro­vides us the lib­er­ty to reuse the par­tic­u­lar
    Con­duct job when­ev­er demand­ed.
    “extends Thread” com­pris­es both thread and project spe­cial behav­ior code. Thus once thread fin­ish­es exe­cu­tion, it can­not be restart .
  3. Object ori­ent­ed Design– Imple­ment­ing Runnable ought to be pre­ferred. It does not spe­cial­iz­ing or mod­i­fy­ing the thread behav­iour. You are giv­ing thread some­thing to oper­ate. We con­clude that Com­po­si­tion is the bet­ter strat­e­gy. Com­po­si­tion means two things A and B sat­is­fies has-a rela­tion­ship.
    “extends Thread” Isn’t a good Object Ori­ent­ed prac­tice
  4. Loose­ly-cou­pled- If u are imple­ment­ing Runnable inter­face then the code will be loose­ly-cou­pled and eas­i­er to read . Because the code will be divid­ed into two class­es. One is Thread for the thread spe­cif­ic code and anoth­er with your Runnable imple­men­ta­tion class for your job that should be con­duct­ed by a thread code. extend­ing Thread class cre­ates the tight­ly cou­pled. Sin­gle class con­tains the rib­bon code as well as the task that needs to be car­ried out by the thread.
  5. Func­tions over­head- extend­ing Thread Means inher­it­ing all the prop­er­ties of the Thread class which we might don’t need. Job could be per­formed eas­i­ly by Runnable with­out the Thread class func­tions over­head.(Read Also : Main thread in Java)
    .