Last active
March 27, 2018 12:39
-
-
Save shailrshah/fdae15a6d39ebbd16879e62c0d037274 to your computer and use it in GitHub Desktop.
Threading example
This file contains hidden or 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 HelloRunnable implements Runnable { | |
@Override | |
public void run() { | |
for(int i = 0; i <= 10; i++) { | |
System.out.println(i + "\t" + Thread.currentThread().getName()); | |
} | |
} | |
} | |
class HelloThread extends Thread { | |
@Override | |
public void run() { | |
for(int i = 0; i <= 10; i++) { | |
System.out.println(i + "\t" + Thread.currentThread().getName()); | |
} | |
} | |
} | |
public class ThreadDemo { | |
public static void main(String[] args) { | |
Runnable runnable = new HelloRunnable(); | |
Thread t1 = new Thread(runnable, "Implements Runnable"); | |
Thread t2 = new HelloThread(); | |
t2.setName("Extends Thread"); | |
t1.start(); | |
t2.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment