ways to implement thread in java code example
Example 1: java thread
public class ClassName extends Thread{
public void run(){
super.run();
}
}
public class Main{
public static void main(String[] args){
ClassName thread = new ClassName();
thread.start();
}
}
Example 2: start thread java
package com.tutorialspoint;
import java.lang.*;
public class ThreadDemo implements Runnable {
Thread t;
ThreadDemo() {
t = new Thread(this, "Admin Thread");
System.out.println("thread = " + t);
System.out.println("Calling run() function... ");
t.start();
}
public void run() {
System.out.println("Inside run()function");
}
public static void main(String args[]) {
new ThreadDemo();
}
}