Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Last active July 11, 2021 09:52
Show Gist options
  • Save wkdalsgh192/958e206a282cdb6e6a9b1b9aca0cb905 to your computer and use it in GitHub Desktop.
Save wkdalsgh192/958e206a282cdb6e6a9b1b9aca0cb905 to your computer and use it in GitHub Desktop.
// 1. create a sub class inherent to Thread class
static class MyThread extends Thread {
@Override
public void run() {
System.out.println("Hello : "+Thread.currentThread().getName());
}
}
MyThread myThread = new MyThread();
myThread.start();
// 2. implement Runnable
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello : "+ Thread.currentThread().getName());
}
});
// 2-1 implement Runnable in functional programming
Thread thread = new Thread(() -> System.out.println("Hello : "+ Thread.currentThread().getName()));
thread.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment