CompletableFuture:让你的代码免受阻塞之苦

Java异步编程利器:CompletableFuture详解 ‌CompletableFuture‌是Java 8中引入的一个类,它实现了Future和CompletionStage接口,用于支持异步编程和非阻塞操作。CompletableFuture提供了丰富的API,使得并发任务的处理变得简单而高效,能够轻松创建、组合和链式调用异步操作,无需关心底层线程管理,从而提升了程序的响应速度和资源利用率‌。 阅读详情

业务复杂一个接口查询多个数据源、通知多方系统导致接口性能是指提升不上去,tomcat线程池日常告急,CPU的利用率却不到百分之50,那肯定不能让他闲着,必须要增加线程让它忙起来,将一个接口的复杂逻辑拆分成多个异步任务提高单接口的吞吐量,这个时候你就要了解下异步编程神器CompletableFuture了,它帮助我们简化异步编程的复杂性,并且提供了函数式编程的能力,可以通过回调的方式处理计算结果,也提供了转换和组合 CompletableFuture 的方法。


前言

通过阅读本篇文章你将了解到:

  • CompletableFuture的使用
  • CompletableFuture异步和同步的性能测试
  • 已经有了Future为什么仍需要在JDK1.8中引入CompletableFuture
  • CompletableFuture的应用场景
  • 对CompletableFuture的使用优化

## 场景说明 查询所有商店某个商品的价格并返回,并且查询商店某个商品的价格的API为同步 一个Shop类,提供一个名为getPrice的同步方法

店铺类:Shop.java

public class Shop {
    private Random random = new Random();
    /**
     * 根据产品名查找价格
     * */
    public double getPrice(String product) {
        return calculatePrice(product);
    }

    /**
     * 计算价格
     *
     * @param product
     * @return
     * */
    private double calculatePrice(String product) {
        delay();
        //random.nextDouble()随机返回折扣
        return random.nextDouble() * product.charAt(0) + product.charAt(1);
    }

    /**
     * 通过睡眠模拟其他耗时操作
     * */
    private void delay() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

复制代码查询商品的价格为同步方法,并通过sleep方法模拟其他操作。这个场景模拟了当需要调用第三方API,但第三方提供的是同步API,在无法修改第三方API时如何设计代码调用提高应用的性能和吞吐量,这时候可以使用CompletableFuture类

CompletableFuture使用

Completable是Future接口的实现类,在JDK1.8中引入

CompletableFuture的创建

  • 使用new方法
CompletableFuture<Double> futurePrice = new CompletableFuture<>();
  • 使用CompletableFuture#completedFuture静态方法创建
public static <U> CompletableFuture<U> completedFuture(U value) {
    return new CompletableFuture<U>((value == null) ? NIL : value);
}

参数的值为任务执行完的结果,一般该方法在实际应用中较少应用

  • 使用 CompletableFuture#supplyAsync静态方法创建supplyAsync有两个重载方法:
/方法一
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
    return asyncSupplyStage(asyncPool, supplier);
}
//方法二
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier,
                                                   Executor executor) {
    return asyncSupplyStage(screenExecutor(executor), supplier);
}
  • 使用CompletableFuture#runAsync静态方法创建runAsync有两个重载方法
//方法一
public static CompletableFuture<Void> runAsync(Runnable runnable) {
    return asyncRunStage(asyncPool, runnable);
}
//方法二
public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor) {
    return asyncRunStage(screenExecutor(executor), runnable);
}

说明:

  • 两个重载方法之间的区别 => 后者可以传入自定义Executor,前者是默认的,使用的ForkJoinPool
  • supplyAsync和runAsync方法之间的区别 => 前者有返回值,后者无返回值
  • Supplier是函数式接口,因此该方法需要传入该接口的实现类,追踪源码会发现在run方法中会调用该接口的方法。因此使用该方法创建- CompletableFuture对象只需重写Supplier中的get方法,在get方法中定义任务即可。又因为函数式接口可以使用Lambda表达式,和new创建CompletableFuture对象相比代码会简洁不少

结果的获取

对于结果的获取CompltableFuture类提供了四种方式

//方式一
public T get()
//方式二
public T get(long timeout, TimeUnit unit)
//方式三
public T getNow(T valueIfAbsent)
//方式四
public T join()

说明:

  • get()和get(long timeout, TimeUnit unit) => 在Future中就已经提供了,后者提供超时处理,如果在指定时间内未获取结果将抛出超时异常
  • getNow => 立即获取结果不阻塞,结果计算已完成将返回结果或计算过程中的异常,如果未计算完成将返回设定的valueIfAbsent值
  • join => 方法里不会抛出异常

示例:

public class AcquireResultTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //getNow方法测试
        CompletableFuture<String> cp1 = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(60 * 1000 * 60 );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            return "hello world";
        });

        System.out.println(cp1.getNow("hello h2t"));

        //join方法测试
        CompletableFuture<Integer> cp2 = CompletableFuture.supplyAsync((()-> 1 / 0));
        System.out.println(cp2.join());

        //get方法测试
        CompletableFuture<Integer> cp3 = CompletableFuture.supplyAsync((()-> 1 / 0));
        System.out.println(cp3.get());
    }
}

说明:

  • 第一个执行结果为hello h2t,因为要先睡上1分钟结果不能立即获取
  • join方法获取结果方法里不会抛异常,但是执行结果会抛异常,抛出的异常为CompletionException
  • get方法获取结果方法里将抛出异常,执行结果抛出的异常为ExecutionException

异常处理

使用静态方法创建的CompletableFuture对象无需显示处理异常,使用new创建的对象需要调用completeExceptionally方法设置捕获到的异常,举例说明:

CompletableFuture completableFuture = new CompletableFuture();
new Thread(() -> {
     try {
         //doSomething,调用complete方法将其他方法的执行结果记录在completableFuture对象中
         completableFuture.complete(null);
     } catch (Exception e) {
         //异常处理
         completableFuture.completeExceptionally(e);
      }
 }).start();

同步方法Pick异步方法查询所有店铺某个商品价格

店铺为一个列表:

private static List<Shop> shopList = Arrays.asList(
        new Shop("BestPrice"),
        new Shop("LetsSaveBig"),
        new Shop("MyFavoriteShop"),
        new Shop("BuyItAll")
);
  • 同步方法:
private static List<String> findPriceSync(String product) {
    return shopList.stream()
            .map(shop -> String.format("%s price is %.2f",
                    shop.getName(), shop.getPrice(product)))  //格式转换
            .collect(Collectors.toList());
}
  • 异步方法:
private static List<String> findPriceAsync(String product) {
    List<CompletableFuture<String>> completableFutureList = shopList.stream()
            //转异步执行
            .map(shop -> CompletableFuture.supplyAsync(
                    () -> String.format("%s price is %.2f",
                            shop.getName(), shop.getPrice(product))))  //格式转换
            .collect(Collectors.toList());

    return completableFutureList.stream()
            .map(CompletableFuture::join)  //获取结果不会抛出异常
            .collect(Collectors.toList());
}
  • 性能测试结果:
Find Price Sync Done in 4141
Find Price Async Done in 1033

异步执行效率提高四倍

为什么仍需要CompletableFuture

在JDK1.8以前,通过调用线程池的submit方法可以让任务以异步的方式运行,该方法会返回一个Future对象,通过调用get方法获取异步执行的结果:

private static List<String> findPriceFutureAsync(String product) {
    ExecutorService es = Executors.newCachedThreadPool();
    List<Future<String>> futureList = shopList.stream().map(shop -> es.submit(() -> String.format("%s price is %.2f",
            shop.getName(), shop.getPrice(product)))).collect(Collectors.toList());

    return futureList.stream()
            .map(f -> {
                String result = null;
                try {
                    result = f.get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                return result;
            }).collect(Collectors.toList());
}

既生瑜何生亮,为什么仍需要引入CompletableFuture?
对于简单的业务场景使用Future完全没有,但是想将多个异步任务的计算结果组合起来,后一个异步任务的计算结果需要前一个异步任务的值等等,使用Future提供的那点API就囊中羞涩,处理起来不够优雅,这时候还是让CompletableFuture以声明式的方式优雅的处理这些需求。虽然 Future 以及相关使用方法提供了异步执行任务的能力,但是对于结果的获取却是很不方便,只能通过阻塞或者轮询的方式得到任务的结果。阻塞的方式显然和我们的异步编程的初衷相违背,轮询的方式又会耗费无谓的 CPU 资源(循环、判断这种指令都会转换成机器指令由CUP解释执行,所以循环是耗费CPU的;IO指令在CUP执行完后就CPU就不管了主要时间消耗在磁盘和内存之间的数据读取过程,不消耗CPU),也不能及时地得到计算结果,并且代码也不优雅,用伪代码表示如下:

while(future.isDone()) {
    result = future.get();
    doSomrthingWithResult(result);
} 

但CompletableFuture提供了API帮助我们实现这样的需求

其他API介绍

whenComplete计算结果的处理

对前面计算结果进行处理,无法返回新值

提供了三个方法
//方法一
public CompletableFuture<T> whenComplete(BiConsumer<? super T,? super Throwable> action)
//方法二
public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)
//方法三
public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
说明
  • BiFunction<? super T,? super U,? extends V> fn参数 => 定义对结果的处理
  • Executor executor参数 => 自定义线程池
  • 以async结尾的方法将会在一个新的线程中执行组合操作
示例
public class WhenCompleteTest {
    public static void main(String[] args) {
        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> "hello");
        CompletableFuture<String> cf2 = cf1.whenComplete((v, e) ->
                System.out.println(String.format("value:%s, exception:%s", v, e)));
        System.out.println(cf2.join());
    }
}

thenApply转换

将前面计算结果的的CompletableFuture传递给thenApply,返回thenApply处理后的结果。可以认为通过thenApply方法实现CompletableFuture至CompletableFuture的转换。白话一点就是将CompletableFuture的计算结果作为thenApply方法的参数,返回thenApply方法处理后的结果

提供了三个方法
//方法一
public <U> CompletableFuture<U> thenApply(
    Function<? super T,? extends U> fn) {
    return uniApplyStage(null, fn);
}

//方法二
public <U> CompletableFuture<U> thenApplyAsync(
    Function<? super T,? extends U> fn) {
    return uniApplyStage(asyncPool, fn);
}

//方法三
public <U> CompletableFuture<U> thenApplyAsync(
    Function<? super T,? extends U> fn, Executor executor) {
    return uniApplyStage(screenExecutor(executor), fn);
}
说明
  • Function<? super T,? extends U> fn参数 => 对前一个CompletableFuture 计算结果的转化操作
  • Executor executor参数 => 自定义线程池
  • 以async结尾的方法将会在一个新的线程中执行组合操作
示例
public class ThenApplyTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> result = CompletableFuture.supplyAsync(ThenApplyTest::randomInteger).thenApply((i) -> i * 8);
        System.out.println(result.get());
    }

    public static Integer randomInteger() {
        return 10;
    }
}

这里将前一个CompletableFuture计算出来的结果扩大八倍

thenAccept结果处理

thenApply也可以归类为对结果的处理,thenAccept和thenApply的区别就是没有返回值

提供了三个方法
//方法一
public CompletableFuture<Void> thenAccept(Consumer<? super T> action) {
    return uniAcceptStage(null, action);
}

//方法二
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action) {
    return uniAcceptStage(asyncPool, action);
}

//方法三
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action,
                                               Executor executor) {
    return uniAcceptStage(screenExecutor(executor), action);
}
说明
  • Consumer<? super T> action参数 => 对前一个CompletableFuture计算结果的操作
  • Executor executor参数 => 自定义线程池
  • 同理以async结尾的方法将会在一个新的线程中执行组合操作
示例
public class ThenAcceptTest {
    public static void main(String[] args) {
        CompletableFuture.supplyAsync(ThenAcceptTest::getList).thenAccept(strList -> strList.stream()
                .forEach(m -> System.out.println(m)));
    }

    public static List<String> getList() {
        return Arrays.asList("a", "b", "c");
    }
}

将前一个CompletableFuture计算出来的结果打印出来

thenCompose异步结果流水化

thenCompose方法可以将两个异步操作进行流水操作

提供了三个方法
//方法一
public <U> CompletableFuture<U> thenCompose(
    Function<? super T, ? extends CompletionStage<U>> fn) {
    return uniComposeStage(null, fn);
}

//方法二
public <U> CompletableFuture<U> thenComposeAsync(
    Function<? super T, ? extends CompletionStage<U>> fn) {
    return uniComposeStage(asyncPool, fn);
}

//方法三
public <U> CompletableFuture<U> thenComposeAsync(
    Function<? super T, ? extends CompletionStage<U>> fn,
    Executor executor) {
    return uniComposeStage(screenExecutor(executor), fn);
}
说明
  • Function<? super T, ? extends CompletionStage> fn参数 => 当前CompletableFuture计算结果的执行
  • Executor executor参数 => 自定义线程池
  • 同理以async结尾的方法将会在一个新的线程中执行组合操作
示例
public class ThenComposeTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> result = CompletableFuture.supplyAsync(ThenComposeTest::getInteger)
                .thenCompose(i -> CompletableFuture.supplyAsync(() -> i * 10));
        System.out.println(result.get());
    }

    private static int getInteger() {
        return 666;
    }

    private static int expandValue(int num) {
        return num * 10;
    }
}
执行流程图

在这里插入图片描述

thenCombine组合结果

thenCombine方法将两个无关的CompletableFuture组合起来,第二个Completable并不依赖第一个Completable的结果

提供了三个方法
//方法一
public <U,V> CompletableFuture<V> thenCombine( 
    CompletionStage<? extends U> other,
    BiFunction<? super T,? super U,? extends V> fn) {
    return biApplyStage(null, other, fn);
}
  //方法二
  public <U,V> CompletableFuture<V> thenCombineAsync(
      CompletionStage<? extends U> other,
      BiFunction<? super T,? super U,? extends V> fn) {
      return biApplyStage(asyncPool, other, fn);
  }

  //方法三
  public <U,V> CompletableFuture<V> thenCombineAsync(
      CompletionStage<? extends U> other,
      BiFunction<? super T,? super U,? extends V> fn, Executor executor) {
      return biApplyStage(screenExecutor(executor), other, fn);
  }
说明
  • CompletionStage<? extends U> other参数 => 新的CompletableFuture的计算结果
  • BiFunction<? super T,? super U,? extends V> fn参数 => 定义了两个CompletableFuture对象完成计算后如何合并结果,该参数是一个函数式接口,因此可以使用Lambda表达式
  • Executor executor参数 => 自定义线程池
  • 同理以async结尾的方法将会在一个新的线程中执行组合操作
示例
public class ThenCombineTest {
    private static Random random = new Random();
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> result = CompletableFuture.supplyAsync(ThenCombineTest::randomInteger).thenCombine(
                CompletableFuture.supplyAsync(ThenCombineTest::randomInteger), (i, j) -> i * j
        );

        System.out.println(result.get());
    }

    public static Integer randomInteger() {
        return random.nextInt(100);
    }
}

将两个线程计算出来的值做一个乘法在返回

执行流程图

在这里插入图片描述

allOf&anyOf组合多个CompletableFuture

方法介绍
//allOf
public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs) {
    return andTree(cfs, 0, cfs.length - 1);
}
//anyOf
public static CompletableFuture<Object> anyOf(CompletableFuture<?>... cfs) {
    return orTree(cfs, 0, cfs.length - 1);
}
说明
  • allOf => 所有的CompletableFuture都执行完后执行计算。
  • anyOf => 任意一个CompletableFuture执行完后就会执行计算
示例
  • allOf方法测试
public class AllOfTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> future1 = CompletableFuture.supplyAsync(() -> {
            System.out.println("hello");
            return null;
        });
        CompletableFuture<Void> future2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("world"); return null;
        });
        CompletableFuture<Void> result = CompletableFuture.allOf(future1, future2);
        System.out.println(result.get());
    }
}

allOf方法没有返回值,适合没有返回值并且需要前面所有任务执行完毕才能执行后续任务的应用场景

  • anyOf方法测试
public class AnyOfTest {
    private static Random random = new Random();
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
            randomSleep();
            System.out.println("hello");
            return "hello";});
        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            randomSleep();
            System.out.println("world");
            return "world";
        });
        CompletableFuture<Object> result = CompletableFuture.anyOf(future1, future2);
        System.out.println(result.get());
   }

    private static void randomSleep() {
        try {
            Thread.sleep(random.nextInt(10));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

复制代码两个线程都会将结果打印出来,但是get方法只会返回最先完成任务的结果。该方法比较适合只要有一个返回值就可以继续执行其他任务的应用场景

注意点

很多方法都提供了异步实现【带async后缀】,但是需小心谨慎使用这些异步方法,因为异步意味着存在上下文切换,可能性能不一定比同步好。如果需要使用异步的方法,先做测试,用测试数据说话!!!
CompletableFuture的应用场景
存在IO密集型的任务可以选择CompletableFuture,IO部分交由另外一个线程去执行。Logback、Log4j2异步日志记录的实现原理就是新起了一个线程去执行IO操作,这部分可以以CompletableFuture.runAsync(()->{ioOperation();})的方式去调用,有关Logback异步日志记录的原理可以参考这篇文章Logback异步日志记录。如果是CPU密集型就不推荐使用了推荐使用并行流

优化空间

supplyAsync执行任务底层实现

public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
    return asyncSupplyStage(asyncPool, supplier);
}
static <U> CompletableFuture<U> asyncSupplyStage(Executor e, Supplier<U> f) {
    if (f == null) throw new NullPointerException();
    CompletableFuture<U> d = new CompletableFuture<U>();
    e.execute(new AsyncSupply<U>(d, f));
    return d;
}

底层调用的是线程池去执行任务,而CompletableFuture中默认线程池为ForkJoinPool

private static final Executor asyncPool = useCommonPool ?
        ForkJoinPool.commonPool() : new ThreadPerTaskExecutor();

ForkJoinPool线程池的大小取决于CPU的核数。之前写的为什么阿里巴巴要禁用Executors创建线程池?文章中提及过,CPU密集型任务线程池大小配置为CPU核心数就可以了,但是IO密集型,线程池的大小由**CPU数量 * CPU利用率 * (1 + 线程等待时间/线程CPU时间)**确定。而CompletableFuture的应用场景就是IO密集型任务,因此默认的ForkJoinPool一般无法达到最佳性能,我们需自己根据业务创建线程池

作者:何甜甜在吗
原文链接:https://juejin.im/post/5dfb5bc951882512420b06c5

【JAVA8】CompletableFuture使用详解 CompletableFuture!让你的代码免受阻塞之苦! 灵活的使用`CompletableFuture`可以让我们感受java8的异步编程之美! 阅读详情

相关推荐

Java8异步类CompletableFuture详解

JDK8引入了一个新的类CompletableFuture

CharlesYooSky的博客 2729

Java多线程之CompletableFuture

文章目录1 CompletableFuture1.1 简介1.2 创建CompletableFuture1.2.1 构造函数创建1.2.2 supplyAsync创建1.2.3 runAsync创建1.3 异步回调方法1.3.1 thenApply / thenAccept / thenRun互相依赖1.3.1.1 thenApply1.3.1.2 thenAccept / thenRun1.3.2 exceptionally有返回1.3.3 whenComplete无返回1.3.4 handle有返回1.

上善若泪 2万+

iTunes登录协议全解析:从抓包到签名验证(含HTTPDebugger避坑指南)

本文深入解析了iTunes登录协议的核心流程,包括sign-sap-setup-cert和sign-sap-setup-buffer等关键请求,并提供了使用HTTPDebugger等工具进行抓包分析时绕过反调试检测的实战技巧与避坑指南。文章详细拆解了PLIST编解码、请求签名验证机制及密码加密逻辑,为网络安全研究和协议逆向提供了完整的技术路径。

weixin_29224309的博客 330

java 异步 CompletableFuture 详解

java 异步 CompletableFuture

lockie的博客 2182

思澈sdk-新建lcd

co5300至此有3个同ID的驱动,在co5300xxxx.c的LCD_DRIVER_EXPORT(co5300, LCD_ID, &lcdc_int_cfg, &CO5300_drv, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT, 2);2 在customer\peripherals\Kconfig_lcd中添加如下配置(注意修改的地方有两个LCD_USING_TFT_CO5300_143)5 在该文件中的config LCD_DPI配置项下添加:(这里300为DPI)

gongyuan073的专栏 1380

Skiplist,B,B+tree,LSM tree

SkipList 理解(如何实现): 即使是有序的链表,查找的时间复杂度也是O(n),但链表不能随机访问所以不适用于二分查找,使得查找的时间复杂度为O(logn)。 于是将有序链表和二分查找结合得到了SkipList,类似于二叉搜索树,这是一种以空间换时间的算法,通过在每个节点中增加向前的指针,从而提升查找效率(如下图所示)。 一开始如a所示,是一个有序的链表,时间复杂度O(n)。随后建立了e所示的SkipList,从最顶层往下查找,可以跳过许多元素,减少查找次数。 ​

weixin_45875458的博客 945

异步神器CompletableFuture:让你的代码免受阻塞之苦

通过阅读本篇文章你将了解到: CompletableFuture的使用 CompletableFure异步和同步的性能测试 已经有了Future为什么仍需要在JDK1.8中引入CompletableFuture CompletableFuture的应用场景 对CompletableFuture的使用优化 场景说明 查询所有商店某个商品的价格并返回,并且查询商店某个商品的价格的API为同步 一个Shop类,提供一个名为getPrice的同步方法 店铺类:Shop.java public cl

LoveSummer 3229

在 ABAP Cloud 中玩转 CL_ABAP_PARALLEL 并行处理:从原理到实战

ABAP并行处理框架CL_ABAP_PARALLEL解析 本文系统介绍了SAP ABAP环境中实现并行处理的CL_ABAP_PARALLEL框架。该框架通过封装异步RFC和对话进程,为开发者提供了面向对象的API,显著提升大批量数据处理的效率。 文章首先分析了ABAP环境需要并行处理的原因:传统的串行处理在面对百万级数据时效率低下。然后详细介绍了CL_ABAP_PARALLEL的设计思路,它是一个"小型线程池"式的同步并行框架,适用于批量计算场景。此外,文章重点讲解了控制并行任务的关键参

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 338

【199期】CompletableFuture:让你的代码免受阻塞之苦​

点击上方“Java精选”,选择“设为星标”别问别人为什么,多问自己凭什么!下方有惊喜,留言必回,有问必答!每天08:15更新文章,每天进步一点点...写在前面通过阅读本篇文章你将了解到...

Java精选 346

药物对接仿真软件:HADDOCK_(5).HADDOCK中蛋白质-配体对接流程

半柔性能量最小化阶段是在刚体能量最小化的基础上,允许配体的部分柔性,通过优化配体的构象来进一步提高对接的准确性。半柔性能量最小化阶段是在刚体能量最小化的基础上,允许配体的部分柔性,通过优化配体的构象来进一步提高对接的准确性。如果是PDB格式,确保文件包含所有必要的原子信息。对接完成后,HADDOCK会生成一系列的输出文件,包括对接后的蛋白质-配体复合物结构文件、能量评分文件和统计分析文件。对接完成后,HADDOCK会生成一系列的输出文件,包括对接后的蛋白质-配体复合物结构文件、能量评分文件和统计分析文件。

kkchenjj的博客 1077

独家开源|RK3588 平台 YOLOv5 Android 源码级解析:NPU 量化、多线程与目标跟踪实战

本文将带你完成一个完整的AI视觉项目:在搭载RK3588芯片的Android开发板上运行实时目标检测与跟踪应用。实战目标:成功运行官方YOLOV5摄像头实时检测案例技术深度:深入理解RKNN开发框架和源码实现核心技能:掌握NPU推理、多线程并发、目标跟踪等关键技术。

m0_71589036的博客 193

代替 Future 的 CompletableFuture:让你的代码免受阻塞之苦

点击下方“IT牧场”,选择“设为星标”作者 |何甜甜在吗来源 |https://juejin.cn/post/6844904024332828685通过阅读本篇文章你将了解到:Comp...

ITMuch的专栏 373

用 YOLOv11‑Seg 做工地实例分割:从 0 起步到效果调优,真香!

这不是一篇“官方文档翻译”,而是一篇。

weixin_43199439的博客 776

学会 CompletableFuture:让你的代码免受阻塞之苦!

????这是一个或许对你有用的社群????一对一交流/面试小册/简历优化/求职解惑,欢迎加入「芋道快速开发平台」知识星球。下面是星球提供的部分资料:《项目实战(视频)》:从书中学,往事中“练”《互联网高频面试题》:面朝简历学习,春暖花开《架构 x 系统设计》:摧枯拉朽,掌控面试高频场景题《精进 Java 学习指南》:系统学习,互联网主流技术栈《必读 Java 源码专栏》:知其然,知其所以然????这是一个或许...

weixin_44421461的博客 324

手把手教你学Simulink——基于Simulink的输入输出线性化精确转矩控制

由于IOFL控制律中实时引入了当前状态的反馈(id​,iq​,ωe​),电感的变化被非线性项自动补偿,转矩仅出现微小幅度的波动(< 2%),展现出极强的参数鲁棒性。:电压方程中的耦合项(ωe​Lq​iq​和 −ωe​Ld​id​)仅通过前馈补偿,当转速 ωe​较高时,微小的前馈误差会导致显著的d-q轴电流交叉耦合;其中,ud​,uq​为定子电压,id​,iq​为定子电流,Rs​为定子电阻,Ls​为定子电感,ωe​为电角速度,ψf​为永磁体磁链,p为极对数。(步长 Ts​=10μs,即100ns?

MHD0815的博客 82

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

system函数阻塞_CompletableFuture:让你的代码免受阻塞之苦

提高应用性能的时候很容易就会想起异步,异步去处理一些任务这样主线程可以尽快响应。写在前面通过阅读本篇文章你将了解到:CompletableFuture的使用CompletableFure异步和同步的性能测试已经有了Future为什么仍需要在JDK1.8中引入CompletableFutureCompletableFuture的应用场景对CompletableFuture的使用优化场景说明查询所有商...

weixin_39928993的博客 161

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

搞懂CompletableFuture:让你的代码免受阻塞之苦​!

写在前面通过阅读本篇文章你将了解到:CompletableFuture的使用CompletableFure异步和同步的性能测试已经有了Future为什么仍需要在JDK1.8中引入CompletableFutureCompletableFuture的应用场景对CompletableFuture的使用优化场景说明查询所有商店某个商品的价格并返回,并且查询商店某个商品的价格的API为同步 一个Shop类...

Java精选 183

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: update select 总是忘...烦死了
下一篇: 进程地址空间和虚拟内存
躺平程序猿
博客等级 码龄8年 4870粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

躺平程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值