image.png

    1. package com.pln.state;
    2. public class TestJoin implements Runnable{
    3. @Override
    4. public void run() {
    5. for (int i = 0; i < 1000; i++) {
    6. System.out.println("我要插队啦"+i);
    7. }
    8. }
    9. public static void main(String[] args) throws InterruptedException {
    10. TestJoin testJoin = new TestJoin();
    11. Thread thread = new Thread(testJoin);
    12. thread.start();
    13. for (int i = 0; i < 100; i++) {
    14. if(i==20){
    15. thread.join();//插队
    16. }
    17. System.out.println("main主方法"+i);
    18. }
    19. }
    20. }