123456789101112131415161718192021222324252627282930313233343536 |
- 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);
- }
- }
|