Skip to content

Instantly share code, notes, and snippets.

@zzh7982
Created January 25, 2021 07:00
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 zzh7982/249883f379b50c5ae50eacd48736b5e2 to your computer and use it in GitHub Desktop.
Save zzh7982/249883f379b50c5ae50eacd48736b5e2 to your computer and use it in GitHub Desktop.
thread-print-abc.java
public static void main(String[] args) throws InterruptedException {
int i = 0;
while (i < 100) {
Thread t1 = new Thread(() -> System.out.print("a"));
Thread t2 = new Thread(() -> {
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("b");
});
Thread t3 = new Thread(() -> {
try {
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("c");
});
t1.start();
t2.start();
t3.start();
t3.join();
i++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment