当前位置: 首页>>代码示例>>Java>>正文


Java CompletableFuture.thenAcceptAsync方法代码示例

本文整理汇总了Java中java.util.concurrent.CompletableFuture.thenAcceptAsync方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.thenAcceptAsync方法的具体用法?Java CompletableFuture.thenAcceptAsync怎么用?Java CompletableFuture.thenAcceptAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CompletableFuture的用法示例。


在下文中一共展示了CompletableFuture.thenAcceptAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ThreadExecutor

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T> CompletableFuture<Void> thenAccept
    (CompletableFuture<T> f, Consumer<? super T> a) {
    return f.thenAcceptAsync(a, new ThreadExecutor());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:CompletableFutureTest.java

示例2: toFuture

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
static <T> Future<T> toFuture(
        final CompletableFuture<T> completableFuture
) {
    final Future<T> future = Future.future();
    completableFuture.thenAcceptAsync(future::complete);
    return future;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:8,代码来源:Async.java

示例3: updateXConnect

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Updates XConnect groups and flows for given key.
 *
 * @param key XConnect key
 * @param prevPorts previous XConnect ports
 * @param ports new XConnect ports
 */
private void updateXConnect(XConnectStoreKey key, Set<PortNumber> prevPorts,
        Set<PortNumber> ports) {
    // remove old filter
    prevPorts.stream().filter(port -> !ports.contains(port)).forEach(port -> {
        revokeFilter(key, ImmutableSet.of(port));
    });
    // install new filter
    ports.stream().filter(port -> !prevPorts.contains(port)).forEach(port -> {
        populateFilter(key, ImmutableSet.of(port));
    });

    CompletableFuture<ObjectiveError> fwdFuture = new CompletableFuture<>();
    CompletableFuture<ObjectiveError> nextFuture = new CompletableFuture<>();

    if (xConnectNextObjStore.containsKey(key)) {
        NextObjective nextObj = xConnectNextObjStore.get(key).value();
        revokeFwd(key, nextObj, fwdFuture);

        fwdFuture.thenAcceptAsync(fwdStatus -> {
            if (fwdStatus == null) {
                log.debug("Fwd removed. Now remove group {}", key);
                revokeNext(key, nextObj, nextFuture);
            }
        });

        nextFuture.thenAcceptAsync(nextStatus -> {
            if (nextStatus == null) {
                log.debug("Installing new group and flow for {}", key);
                populateFwd(key, populateNext(key, ports));
            }
        });
    } else {
        log.warn("NextObj for {} does not exist in the store.", key);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:43,代码来源:XConnectHandler.java

示例4: main

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public static void main(String[] args) {

		System.out.printf("Main: Start\n");
		CompletableFuture<Integer> seedFuture = new CompletableFuture<>();
		Thread seedThread = new Thread(new SeedGenerator(seedFuture));
		seedThread.start();

		System.out.printf("Main: Getting the seed\n");
		int seed = 0;
		try {
			seed = seedFuture.get();
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		System.out.printf("Main: The seed is: %d\n", seed);

		System.out.printf("Main: Launching the list of numbers generator\n");
		NumberListGenerator task = new NumberListGenerator(seed);
		CompletableFuture<List<Long>> startFuture = CompletableFuture.supplyAsync(task);

		System.out.printf("Main: Launching step 1\n");
		CompletableFuture<Long> step1Future = startFuture.thenApplyAsync(list -> {
			System.out.printf("%s: Step 1: Start\n", Thread.currentThread().getName());
			long selected = 0;
			long selectedDistance = Long.MAX_VALUE;
			long distance;
			for (Long number : list) {
				distance = Math.abs(number - 1000);
				if (distance < selectedDistance) {
					selected = number;
					selectedDistance = distance;
				}
			}
			System.out.printf("%s: Step 1: Result - %d\n", Thread.currentThread().getName(), selected);
			return selected;
		});

		System.out.printf("Main: Launching step 2\n");
		CompletableFuture<Long> step2Future = startFuture
				.thenApplyAsync(list -> list.stream().max(Long::compare).get());

		CompletableFuture<Void> write2Future = step2Future.thenAccept(selected -> {
			System.out.printf("%s: Step 2: Result - %d\n", Thread.currentThread().getName(), selected);
		});

		System.out.printf("Main: Launching step 3\n");
		NumberSelector numberSelector = new NumberSelector();
		CompletableFuture<Long> step3Future = startFuture.thenApplyAsync(numberSelector);

		System.out.printf("Main: Waiting for the end of the three steps\n");
		CompletableFuture<Void> waitFuture = CompletableFuture.allOf(step1Future, write2Future, step3Future);
		CompletableFuture<Void> finalFuture = waitFuture.thenAcceptAsync((param) -> {
			System.out.printf("Main: The CompletableFuture example has been completed.");
		});

		finalFuture.join();

	}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:59,代码来源:Main.java

示例5:

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
public <T> CompletableFuture<Void> thenAccept
    (CompletableFuture<T> f, Consumer<? super T> a) {
    return f.thenAcceptAsync(a);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:CompletableFutureTest.java


注:本文中的java.util.concurrent.CompletableFuture.thenAcceptAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。