Skip to content

Instantly share code, notes, and snippets.

@SalithaUCSC
Last active March 24, 2020 12:42
Two methods of Thread implementation
class ThreadOne extends Thread {
public void run(){
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName()+" => "+i);
}
}
}
class ThreadTwo implements Runnable {
public void run(){
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName()+" => "+i);
}
}
}
public class ThreadApp {
public static void main(String[] args) {
ThreadOne threadOne = new ThreadOne();
threadOne.start();
Thread threadTwo = new Thread(new ThreadTwo());
threadTwo.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment