Skip to content

Instantly share code, notes, and snippets.

@shailrshah
Last active March 27, 2018 12:39
Show Gist options
  • Save shailrshah/fdae15a6d39ebbd16879e62c0d037274 to your computer and use it in GitHub Desktop.
Save shailrshah/fdae15a6d39ebbd16879e62c0d037274 to your computer and use it in GitHub Desktop.
Threading example
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