package com.xjrsoft.xjrsoftboot;

import org.apache.tools.ant.taskdefs.Sleep;
import org.junit.jupiter.api.Test;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureTest {

    @Test
    public void CompletableFutureTest() throws InterruptedException {
        CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(2000); // 暂停2秒
                System.out.println(Thread.currentThread());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(1);
        });

        CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(1000); // 暂停1秒
                System.out.println(Thread.currentThread());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println(2);
        });


        Thread.sleep(1000000);
    }
}
