CompletableFuture异步任务编排用法和详解-程序员宅基地

技术标签: spring  spring boot  java  Java基础  多线程  

在工作中,常常会调用多个服务或者方法去获取不同的数据,如果传统做法就是串行一个个获取,然后封装返回。我们可以尝试使用CompletableFuture,将多个操作交给异步线程执行,然后主线程等待最长任务完成,将所有结果一并返回即可。

Future局限性

当我们得到包含结果的Future时,我们可以使用get方法等待线程完成并获取返回值,但我们都知道future.get()是阻塞的方法,会一直等到线程执行完毕拿到返回值。我们可以看到FutureTask中的get方法,就是循环代码直到线程执行完成返回。

  /**
     * Awaits completion or aborts on interrupt or timeout.
     *
     * @param timed true if use timed waits
     * @param nanos time to wait, if timed
     * @return state upon completion
     */
    private int awaitDone(boolean timed, long nanos) throws InterruptedException {
    
        final long deadline = timed ? System.nanoTime() + nanos : 0L;
        WaitNode q = null;
        boolean queued = false;
        for (;;) {
    
        	//循环 省略代码
        	...
        }

我们考虑一种场景,如果我们执行完该异步任务1需要拿到返回值,然后使用该返回值执行其他异步调用2,那么我们就需要在主线程阻塞等待异步任务1完成,然后交由执行异步任务2,然后继续阻塞等待任务2的返回。这样不仅阻塞主线程,而且性能差

CompletableFuture介绍

什么是CompletableFuture:CompletableFuture结合了Future的优点,提供了非常强大的Future的扩展功能,可以帮助我们简化异步编程的复杂性,提供了函数式编程的能力,可以通过回调的方式处理计算结果,并且提供了转换和组合CompletableFuture的方法。

函数式编程:使用Functional Interface作为参数,可使用lambda表达式建议实现,编程便捷,之前有讲解过。

常用的辅助方法

  1. isCompletedExceptionally:该CompletableFuture是否异常结束。
// 包括取消cancel、显示调用completeExceptionally、中断。
public boolean isCompletedExceptionally() {
    
        Object r;
        return ((r = result) instanceof AltResult) && r != NIL;
    }
  1. isCancelled:该CompletableFuture是否在正常执行完成前被取消。
 public boolean isCancelled() {
    
        Object r;
        // 判断异常是否是CancellationException
        return ((r = result) instanceof AltResult) &&
            (((AltResult)r).ex instanceof CancellationException);
 }
  1. isDone:该CompletableFuture是否已经执行结束包括产生异常和取消。
 public boolean isDone() {
    
       return result != null;
 }
  1. get:阻塞获取CompletableFuture结果
 public T get() throws InterruptedException, ExecutionException {
    
        Object r;
        return reportGet((r = result) == null ? waitingGet(true) : r);
 }
  1. join:阻塞获取CompletableFuture结果
 public T join() {
    
        Object r;
        return reportJoin((r = result) == null ? waitingGet(false) : r);
 }

join() 与get() 区别在于join() 返回计算的结果或者抛出一个unchecked异常(CompletionException),而get() 返回一个具体的异常.

CompletableFuture构建

CompletableFuture有无参数的构造方法,这个时候创建的是未完成的CompletableFuture。使用get会一直阻塞主线程。

所以我们一般使用静态方法来创建实例。

// 无入参有返回值
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier);
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor);
// 无入参无返回值,简单的执行
public static CompletableFuture<Void> runAsync(Runnable runnable);
public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor);

我们注意到每种方法都有一个重构的方法。Executor参数可以手动指定线程池,否则默认ForkJoinPool.commonPool()系统级公共线程池。


【注意】:默认的commonPool的这些线程都是守护线程。我们在编程的时候需要谨慎使用守护线程,如果将我们普通的用户线程设置成守护线程,当我们的程序主线程结束,JVM中不存在其余用户线程,那么CompletableFuture的守护线程会直接退出,造成任务无法完成的问题!!

CompletableFuture常用Api

我们后续讲解的api一般会有三种相似的方法。我就只演示第三种。

  1. xxx(method);
  2. xxxAsync(method);
  3. xxxAsync(method, executor)
    三种的区别就是第一种同步执行由主线程执行,第二种异步交由默认线程池,第三种异步交由创建的线程池。

1.构建CompletableFuture实例

现在就将CompletableFuture来试着使用。先从基本的构建开始。

/**
* 1.run + runAsync + supply + supplyAsync
*/
/** 1.异步运行交由默认线程池(forkjoinpool)无入参无返回值run
*   2.异步运行交由创建线程池(threadPoolExecutor)无入参无返回值run
*/
CompletableFuture<Void> run = CompletableFuture.runAsync(() ->
        System.out.println("completablefuture runs asynchronously"));

CompletableFuture<Void> runCustomize = CompletableFuture.runAsync(() ->
        System.out.println("completablefuture runs asynchronously in customize threadPool"
        ), threadPoolExecutor);


//================下面是supply===================
/** 1.异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
*   2.异步运行交由自己创建的线程池 无入参有返回值supply
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously");
    return "success";
});

CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success";
}, threadPoolExecutor);

result

completablefuture runs asynchronously
completablefuture runs asynchronously in customize threadPool
completablefuture supplys asynchronously
completablefuture supplys asynchronously in customize threadPool

前两种的CompletableFuture是没有值的,所以当后续链式调用想使用的时候入参是null的。

2.whenComplete

考虑当我们在CompletableFuture执行结束的时候,希望能够得到执行结果、或者异常,然后对结果或者异常做进一步处理。那么我们就需要使用到whenComplete。

  /**
  * 入参是BiConsumer,第一个参数是上一步结果、第二个是上一步执行的异常
  */
 CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
          int a = 1/0;
          System.out.println("completablefuture supplys asynchronously");
          return "success";
 });
 CompletableFuture<String> complete = supply.whenCompleteAsync((result, throwable) -> {
    
     System.out.println("whenComplete: " + result + " throws " + throwable);
 });

result:

whenComplete: null throws java.util.concurrent.CompletionException: java.lang.ArithmeticException: / by zero

3.handle

handle和whenComplete入参是一样的,但是它可以在执行完成后返回执行结果,而whenComplete只能处理无法返回。

public <U> CompletableFuture<U>     handle(BiFunction<? super T,Throwable,? extends U> fn)
public <U> CompletableFuture<U>     handleAsync(BiFunction<? super T,Throwable,? extends U> fn)
public <U> CompletableFuture<U>     handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)

example:

/**
* 入参是BiFunction 第一个参数是上一步结果、第二个是上一步执行的异常 
* 返回值可以是任何类型
*/
CompletableFuture<String> handleAsyncCustomize = supply.handleAsync((a, throwable) -> {
    
            System.out.println("handleAsyncCustomize: " + a + " throws " + throwable);
            return "handleAsync success";
}, threadPoolExecutor);

System.out.println(handleAsyncCustomize.get());

result:

handleAsyncCustomize: success throws null
handleAsync success

4.thenApply

thenApply又和handle很类似,有入参也有返回值的,但是他只有一个入参,无法处理上一异步任务异常的情况。如果发生异常get的时候会报错。

public <U> CompletableFuture<U>     thenApply(Function<? super T,? extends U> fn)
public <U> CompletableFuture<U>     thenApplyAsync(Function<? super T,? extends U> fn)
public <U> CompletableFuture<U>     thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
/**
* Function 入参是第一个异步任务执行结果、出参是返回值
* 若异步任务1异常 则2无法执行 get会报错
*/
 CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
     System.out.println("completablefuture supplys asynchronously in customize threadPool");
     int a = 1/0;
     return "success";
 }, threadPoolExecutor);

 CompletableFuture<String> applyAsyncCustomize = supplyCustomize.thenApplyAsync(a -> {
    
     System.out.println("applyAsyncCustomize " + a);
     return "success";
 }, threadPoolExecutor);
 System.out.println(applyAsyncCustomize.get());

result:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ArithmeticException: / by zero
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)
	at CompletableFutureTask.main.main(main.java:48)
Caused by: java.lang.ArithmeticException: / by zero
	at CompletableFutureTask.main.lambda$main$3(main.java:40)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

5.thenAccept

thenAccept是有入参无返回值,如果继续链式调用那么下一个异步任务将会得到null值。

public CompletableFuture<Void>  thenAccept(Consumer<? super T> action)
public CompletableFuture<Void>  thenAcceptAsync(Consumer<? super T> action)
public CompletableFuture<Void>  thenAcceptAsync(Consumer<? super T> action, Executor executor)

example:

/**
*	Consumer第一个入参是上一步返回结果,若没返回结果则为null
*	无返回值
*/
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
   System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success";
}, threadPoolExecutor);

CompletableFuture<Void> applyAsyncCustomize = supplyCustomize.thenAcceptAsync(a ->{
    
    System.out.println("accept " + a);
}, threadPoolExecutor);
System.out.println(applyAsyncCustomize.get());

result:

completablefuture supplys asynchronously in customize threadPool
accept success
null

6.thenCompose

和thenCombine有所不同,thenCombine是组合两个CompletableFuture返回结果进行异步处理,而thenCompose则是根据第一个返回结果,封装成新的CompletableFuture返回

example:

CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
     System.out.println("completablefuture supplys asynchronously");
     return "success";
 });
 CompletableFuture<String> future = supply.thenComposeAsync(a -> {
    
     String name = a + " or fail";
     return CompletableFuture.supplyAsync(() -> {
    
         return name;
     });
 });
 System.out.println(future.get());

result:

completablefuture supplys asynchronously in customize threadPool
success or fail

7.exceptionally

当发生异常时候的处理,注意异常后返回值类型需要和发生异常的CF返回值类型一致,相当于一种服务降级的思想。

example:

/**
*	发生异常时候,返回0
*/
CompletableFuture<Integer> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
     int a = 1/0;
     System.out.println("completablefuture supplys asynchronously in customize threadPool");
     return 2;
 }, threadPoolExecutor).exceptionally(a->{
    
     System.out.println(a);
     return 0;
 });

 System.out.println(supplyCustomize.get());

result:

completablefuture runs asynchronously in customize threadPool
java.util.concurrent.CompletionException: java.lang.ArithmeticException: / by zero
0

CompletableFuture组合式Api-任务全完成

1.thenCombine

thenCombine是组合式任务,上面的CompletableFuture使用是链式完成,当完成第一个时候,根据第一个执行结果进行下一步异步调用,而组合式异步,可以做到两个异步任务完全独立,只有当他们都完成时候才会继续执行。

example:

/**
*	BiFunction入参,两个CF的返回结果作为入参,有返回值
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
	System.out.println("completablefuture supplys asynchronously");
    return "success";
});
// 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success";
}, threadPoolExecutor);

CompletableFuture<String> future = supply.thenCombine(supplyCustomize, (a, b) -> {
    
    return "thenCombine result: " + a + "-" + b;
});
System.out.println(future.get());

result:

completablefuture supplys asynchronously
completablefuture supplys asynchronously in customize threadPool
thenCombine result: success-success

2.thenAcceptBoth

thenAcceptBoth和thenCombine区别就是没有返回值,将两个CF返回值进行处理,没有返回值

example:

/**
*	接受CF、BiConsumer,无返回值
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously");
    return "success";
});
// 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success";
}, threadPoolExecutor);

CompletableFuture<Void> bothAsync = supplyCustomize.thenAcceptBothAsync(supply, (a, b) -> {
    
    System.out.println("thenAcceptBoth result " + a + "-" + b);
}, threadPoolExecutor);

result:

completablefuture supplys asynchronously
completablefuture supplys asynchronously in customize threadPool
thenAcceptBoth result success-success
null

3.runAfterBoth

无入参无返回值,只会在前面两者都运行完成后才会执行runAfterBoth的方法,我们可以在任一CF模拟长时间运行进行测试。

example:

CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
     System.out.println("completablefuture supplys asynchronously");
     return "success";
 });
 // 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
 CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
     System.out.println("completablefuture supplys asynchronously in customize threadPool");
     return "success";
 }, threadPoolExecutor);
 CompletableFuture<Void> bothAsync = supply.runAfterBothAsync(supplyCustomize, () -> {
    
     System.out.println("run After Both Async");
 });

result:

completablefuture supplys asynchronously
completablefuture supplys asynchronously in customize threadPool
run After Both Async

CompletableFuture组合式Api-任一任务完成

1.acceptEither

和thenAcceptBoth对应,两个CompletableFuture任一执行完成,就会继续下一步异步任务

example:

/**
*	任务一耗时长,所以当任务二完成就会执行acceptEitherAsync
*	参数 Consumer 入参为执行完成任务返回值
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    try {
    
        TimeUnit.SECONDS.sleep(2);
    } catch (InterruptedException e) {
    
        e.printStackTrace();
    }
    System.out.println("completablefuture supplys asynchronously");
    return "success1";
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success2";
}, threadPoolExecutor);
CompletableFuture<Void> future = supply.acceptEitherAsync(supplyCustomize, a -> {
    
    System.out.println("acceptEither result " + a);
});

result:

completablefuture supplys asynchronously in customize threadPool
acceptEither result success2
completablefuture supplys asynchronously

2.applyToEither

对应thenCombine,两个CompletableFuture任一执行完成,就会继续下一步异步任务

example:

/**
*	参数为Function,有入参也有返回值
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    try {
    
        TimeUnit.SECONDS.sleep(2);
    } catch (InterruptedException e) {
    
        e.printStackTrace();
    }
    System.out.println("completablefuture supplys asynchronously");
    return "success1";
});
// 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success2";
}, threadPoolExecutor);
CompletableFuture<String> future = supply.applyToEither(supplyCustomize, a -> {
    
    System.out.println("acceptEither result " + a);
    return "appleTo " + a;
});

3.runAfterEither

对应runAfterBoth,两个CompletableFuture任一执行完成,就会继续下一步异步任务

/**
*	runnable 无入参无返回值
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    try {
    
        TimeUnit.SECONDS.sleep(2);
    } catch (InterruptedException e) {
    
        e.printStackTrace();
    }
    System.out.println("completablefuture supplys asynchronously");
    return "success1";
});
// 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success2";
}, threadPoolExecutor);
CompletableFuture<Void> future = supply.runAfterEitherAsync(supplyCustomize, () -> {
    
    System.out.println("runAfterEither result ");
});

CompletableFuture之allOf|anyOf

1.allOf

所有完成get方法才能获得返回值,返回值是null,每个任务返回值需要调用每个CompletableFuture。

example:

/**
*	当所有任务完成后,返回null,具体每个任务返回值,需要调用具体
*	异步任务获取
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
    try {
    
        TimeUnit.SECONDS.sleep(2);
    } catch (InterruptedException e) {
    
        e.printStackTrace();
    }
    System.out.println("completablefuture supplys asynchronously");
    return "success1";
});
CompletableFuture<String> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
    System.out.println("completablefuture supplys asynchronously in customize threadPool");
    return "success2";
}, threadPoolExecutor);
CompletableFuture<Void> allOf = CompletableFuture.allOf(supply, supplyCustomize);
allOf.get();
System.out.println(supplyCustomize.get() + "=>" + supply.get());

result:

completablefuture supplys asynchronously in customize threadPool
completablefuture supplys asynchronously
success2==success1

2.anyOf

/**
* 任一先执行完毕的结果将会先返回
*/
CompletableFuture<String> supply = CompletableFuture.supplyAsync(() -> {
    
try {
    
    TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
    
    e.printStackTrace();
}
	System.out.println("completablefuture supplys asynchronously");
	return "success1";
});
// 异步运行交由默认线程池(forkjoinpool)无入参有返回值supply
CompletableFuture<Integer> supplyCustomize = CompletableFuture.supplyAsync(() -> {
    
	System.out.println("completablefuture supplys asynchronously in customize threadPool");
	return 2;
}, threadPoolExecutor);
CompletableFuture<Object> anyOf = CompletableFuture.anyOf(supply, supplyCustomize);
System.out.println(anyOf.get());

result:先执行完所以先返回2

completablefuture supplys asynchronously in customize threadPool
2
completablefuture supplys asynchronously

总结

CompletableFuture丰富的异步调用方法,可以帮助我们避免使用主线程来将多个异步任务连结,提高程序性能,加快响应速度。同时优秀的异常处理机制,在异步调用出错过程中也能完美解决。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40922616/article/details/121045841

智能推荐

c# 调用c++ lib静态库_c#调用lib-程序员宅基地

文章浏览阅读2w次,点赞7次,收藏51次。四个步骤1.创建C++ Win32项目动态库dll 2.在Win32项目动态库中添加 外部依赖项 lib头文件和lib库3.导出C接口4.c#调用c++动态库开始你的表演...①创建一个空白的解决方案,在解决方案中添加 Visual C++ , Win32 项目空白解决方案的创建:添加Visual C++ , Win32 项目这......_c#调用lib

deepin/ubuntu安装苹方字体-程序员宅基地

文章浏览阅读4.6k次。苹方字体是苹果系统上的黑体,挺好看的。注重颜值的网站都会使用,例如知乎:font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, W..._ubuntu pingfang

html表单常见操作汇总_html表单的处理程序有那些-程序员宅基地

文章浏览阅读159次。表单表单概述表单标签表单域按钮控件demo表单标签表单标签基本语法结构<form action="处理数据程序的url地址“ method=”get|post“ name="表单名称”></form><!--action,当提交表单时,向何处发送表单中的数据,地址可以是相对地址也可以是绝对地址--><!--method将表单中的数据传送给服务器处理,get方式直接显示在url地址中,数据可以被缓存,且长度有限制;而post方式数据隐藏传输,_html表单的处理程序有那些

PHP设置谷歌验证器(Google Authenticator)实现操作二步验证_php otp 验证器-程序员宅基地

文章浏览阅读1.2k次。使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。下载谷歌验证类库文件放到项目合适位置(我这边放在项目Vender下面)https://github.com/PHPGangsta/GoogleAuthenticatorPHP代码示例://引入谷_php otp 验证器

【Python】matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距-程序员宅基地

文章浏览阅读4.3k次,点赞5次,收藏11次。matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距

docker — 容器存储_docker 保存容器-程序员宅基地

文章浏览阅读2.2k次。①Storage driver 处理各镜像层及容器层的处理细节,实现了多层数据的堆叠,为用户 提供了多层数据合并后的统一视图②所有 Storage driver 都使用可堆叠图像层和写时复制(CoW)策略③docker info 命令可查看当系统上的 storage driver主要用于测试目的,不建议用于生成环境。_docker 保存容器

随便推点

网络拓扑结构_网络拓扑csdn-程序员宅基地

文章浏览阅读834次,点赞27次,收藏13次。网络拓扑结构是指计算机网络中各组件(如计算机、服务器、打印机、路由器、交换机等设备)及其连接线路在物理布局或逻辑构型上的排列形式。这种布局不仅描述了设备间的实际物理连接方式,也决定了数据在网络中流动的路径和方式。不同的网络拓扑结构影响着网络的性能、可靠性、可扩展性及管理维护的难易程度。_网络拓扑csdn

JS重写Date函数,兼容IOS系统_date.prototype 将所有 ios-程序员宅基地

文章浏览阅读1.8k次,点赞5次,收藏8次。IOS系统Date的坑要创建一个指定时间的new Date对象时,通常的做法是:new Date("2020-09-21 11:11:00")这行代码在 PC 端和安卓端都是正常的,而在 iOS 端则会提示 Invalid Date 无效日期。在IOS年月日中间的横岗许换成斜杠,也就是new Date("2020/09/21 11:11:00")通常为了兼容IOS的这个坑,需要做一些额外的特殊处理,笔者在开发的时候经常会忘了兼容IOS系统。所以就想试着重写Date函数,一劳永逸,避免每次ne_date.prototype 将所有 ios

如何将EXCEL表导入plsql数据库中-程序员宅基地

文章浏览阅读5.3k次。方法一:用PLSQL Developer工具。 1 在PLSQL Developer的sql window里输入select * from test for update; 2 按F8执行 3 打开锁, 再按一下加号. 鼠标点到第一列的列头,使全列成选中状态,然后粘贴,最后commit提交即可。(前提..._excel导入pl/sql

Git常用命令速查手册-程序员宅基地

文章浏览阅读83次。Git常用命令速查手册1、初始化仓库git init2、将文件添加到仓库git add 文件名 # 将工作区的某个文件添加到暂存区 git add -u # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,不处理untracked的文件git add -A # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,包括untracked的文件...

分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120-程序员宅基地

文章浏览阅读202次。分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120

【C++缺省函数】 空类默认产生的6个类成员函数_空类默认产生哪些类成员函数-程序员宅基地

文章浏览阅读1.8k次。版权声明:转载请注明出处 http://blog.csdn.net/irean_lau。目录(?)[+]1、缺省构造函数。2、缺省拷贝构造函数。3、 缺省析构函数。4、缺省赋值运算符。5、缺省取址运算符。6、 缺省取址运算符 const。[cpp] view plain copy_空类默认产生哪些类成员函数

推荐文章

热门文章

相关标签