Thread
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(()->{
System.out.println("dddddd");
});
thread.start();
}
}
There are two ways to create Java Thread
- Extend Thread class
- Implement Runnable interface
Create Thread by extending Thread class
public class Main {
public static void main(String[] args) {
Task1 task1 = new Task1();
task1.start();
}
}
class Task1 extends Thread{
public void run(){
System.out.println("ddddd");
}
}
Create Thread by implementing Runnable class
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(new Task1());
thread.start();
}
}
class Task1 implements Runnable{
public void run(){
System.out.println("ddddd");
}
}