Last active
March 24, 2020 12:42
Two methods of Thread implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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