0

i'm currently studying Java and i want to know what is the difference between implementing Runnable to a class and declaring a new thread and executing what you need inside.

Thread t = new Thread(){

    public void run() {
    //code here
    }
};
t.start();

vs

Thread t = new Thread(My_class_with_runnable_implementation);
t.start();
  • 1
    Does this answer your question? ["implements Runnable" vs "extends Thread" in Java](https://stackoverflow.com/questions/541487/implements-runnable-vs-extends-thread-in-java) – Eduardo Pascual Aseff Mar 21 '20 at 03:30
  • I don't want to extends Thread , i would like to call an constructor inside – Mathieu Ricard Mar 21 '20 at 03:31
  • Besides those (older) answers, you also want to look at `Callable` which is a new interface like `Runnable` that you should consider using. Also besides using a `Thread` look at `ExecutorService` and `ThreadPool`. – markspace Mar 21 '20 at 03:32

0 Answers0