Created
January 25, 2021 07:00
-
-
Save zzh7982/249883f379b50c5ae50eacd48736b5e2 to your computer and use it in GitHub Desktop.
thread-print-abc.java
This file contains 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
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