Skip to content

Instantly share code, notes, and snippets.

@frekele
Last active October 20, 2019 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frekele/71b4001734b2fff2f3c36922066e5098 to your computer and use it in GitHub Desktop.
Save frekele/71b4001734b2fff2f3c36922066e5098 to your computer and use it in GitHub Desktop.
ThreadDemo01
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main {
public static void main(String[] args) {
new MyThread().start();
MyRunnable myRunnable = new MyRunnable();
new Thread(myRunnable).start();
for (int i = 0; i < 10; i++) {
System.out.println("Main: " + i);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
class MyThread extends Thread {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("My Thread: " + i);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("MyRunnable: " + i);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(MyRunnable.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
@frekele
Copy link
Author

frekele commented Oct 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment