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


Java FutureTask类代码示例

本文整理汇总了Java中java.util.concurrent.FutureTask的典型用法代码示例。如果您正苦于以下问题:Java FutureTask类的具体用法?Java FutureTask怎么用?Java FutureTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: runFuture

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Test
public void runFuture() {
    for (int i = 0; i < 500; i++) {
        CompositeDisposable set = new CompositeDisposable();
        final ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
        set.add(run);

        final FutureTask<Void> ft = new FutureTask<Void>(Functions.EMPTY_RUNNABLE, null);

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                run.call();
            }
        };

        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                run.setFuture(ft);
            }
        };

        TestCommonHelper.race(r1, r2);
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:27,代码来源:ScheduledRunnableTest.java

示例2: func_181617_a

import java.util.concurrent.FutureTask; //导入依赖的package包/类
public static <V> V func_181617_a(FutureTask<V> p_181617_0_, Logger p_181617_1_)
{
    try
    {
        p_181617_0_.run();
        return p_181617_0_.get();
    }
    catch (ExecutionException executionexception)
    {
        p_181617_1_.fatal((String)"Error executing task", (Throwable)executionexception);
    }
    catch (InterruptedException interruptedexception)
    {
        p_181617_1_.fatal((String)"Error executing task", (Throwable)interruptedexception);
    }

    return (V)null;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:19,代码来源:Util.java

示例3: waitForTasksCompleted

import java.util.concurrent.FutureTask; //导入依赖的package包/类
private Set<Location> waitForTasksCompleted() {
    try {
        Set<Location> targets = new HashSet<>();
        FutureTask<Set<Location>> task;
        while ((task = tasks.poll()) != null) {
            // wait for completion
            if (!task.isDone())
                targets.addAll(task.get());
        }
        return targets;
    } catch (InterruptedException|ExecutionException e) {
        throw new Error(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:DependencyFinder.java

示例4: call

import java.util.concurrent.FutureTask; //导入依赖的package包/类
private <T> Future<T> call(Callable callable, boolean async){
    if(async){
         return Pool.submit(callable);
    }else{
        FutureTask<T> future = new FutureTask(callable);
        future.run();
        return future;
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:10,代码来源:OffsetLimitInterceptor.java

示例5: textProperty

import java.util.concurrent.FutureTask; //导入依赖的package包/类
public StringProperty textProperty() throws InterruptedException, ExecutionException {
    if (Platform.isFxApplicationThread()) {
        return ((javafx.scene.control.Button) body).textProperty();
    }
    final FutureTask<StringProperty> task = new FutureTask<>(() -> ((javafx.scene.control.Button) body).textProperty());
    Platform.runLater(task);
    return task.get();
}
 
开发者ID:whitewoodcity,项目名称:xbrowser,代码行数:9,代码来源:Button.java

示例6: afterExecute

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Override
protected void afterExecute(Runnable task, Throwable exception) {
  if (task instanceof FutureTask<?>) {
    FutureTask<?> futureTask = (FutureTask<?>) task;
    if (!futureTask.isCancelled()) {
      try {
        futureTask.get();
      } catch (ExecutionException ee) {
        exception = ee.getCause();
      } catch (InterruptedException ie) {
        exception = ie;
      }
    }
  }
  if (exception != null) {
    LOG.error("Exception during execution of task in DeletionService",
      exception);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:DeletionService.java

示例7: EWFOutput

import java.util.concurrent.FutureTask; //导入依赖的package包/类
/**
 * Creates a new EWFOutput with the given parameters.
 * @param toImage The device this image is of.
 * @param chunkQueue The source of data chunks to build the {@link SectorsSection Sectors} segments with.
 * @param outputFile The file to write the output to. Should end in .E01.
 * @param md5Hash The source of the MD5 digest hash.
 * @param sha1Hash The source of the SHA1 digest hash.
 * @param options The options used for this image.
 * @throws IOException
 */
public EWFOutput(Device toImage, BlockingQueue<Future<DataChunk>> chunkQueue, File outputFile,
        FutureTask<byte[]> md5Hash, FutureTask<byte[]> sha1Hash, AdvancedOptions options) throws IOException {
    super("EWFWriter");
    this.fileNumber = 1;
    this.outputFile = outputFile;
    this.expectedSize = toImage.getSize();
    this.serialNumber = toImage.getSerialNumber();
    this.volumeManager = new VolumeSectionManager(toImage);
    if (!outputFile.exists()) {
        if (this.outputFile.getParentFile() != null) {
            this.outputFile.getParentFile().mkdirs();
        }
        this.outputFile.createNewFile();
    }
    this.md5HashSource = md5Hash;
    this.sha1HashSource = sha1Hash;
    currentOutputFile = new RandomAccessFile(this.outputFile.getAbsolutePath(), "rw");
    currentOutputFile.setLength(0);
    this.chunkQueue = chunkQueue;
    this.sectorSize = 512; // TODO: remove hardcoded
    this.options = options;
    this.startTime = LocalDateTime.now();
}
 
开发者ID:ciphertechsolutions,项目名称:IO,代码行数:34,代码来源:EWFOutput.java

示例8: run

import java.util.concurrent.FutureTask; //导入依赖的package包/类
public void run(Consumer<HttpResponse> consumer) throws IOException {
System.out.println("Expecting a response after GET from: " + this.url.toString() + "\n\n");
try (SocketChannel socketChannel = SocketChannel.open(this.address)) {
    socketChannel.configureBlocking(true);
    writeGetRequestTo(socketChannel);

    FutureTask<Void> futureTask = HttpResponseReader.fromChannel(socketChannel, consumer);

    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.submit(futureTask);
    executor.awaitTermination(this.timeoutSeconds, TimeUnit.SECONDS);
    executor.shutdown();
    System.out.println("\n\nExecutor shutdown after waiting: " + this.timeoutSeconds + "s.");
} catch (InterruptedException e) {
    System.out.println("Error occured during task execution: " + e.getMessage());
}
   }
 
开发者ID:Oliver-Loeffler,项目名称:NIOHttp,代码行数:18,代码来源:FutureDemo.java

示例9: resolve

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Override
public java.util.concurrent.Future<ProjectProblemsProvider.Result> resolve() {
    ProjectProblemsProvider.Result res;
    if (action != null) {
        action.actionPerformed(null);
        String text = (String) action.getValue(ACT_START_MESSAGE);
        if (text != null) {
            res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED, text);
        } else {
            res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.RESOLVED);
        }
    } else {
        res = ProjectProblemsProvider.Result.create(ProjectProblemsProvider.Status.UNRESOLVED, "No resolution for the problem");
    }
    RunnableFuture<ProjectProblemsProvider.Result> f = new FutureTask(new Runnable() {
        @Override
        public void run() {
        }
    }, res);
    f.run();
    return f;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JUnitProjectOpenedHook.java

示例10: main

import java.util.concurrent.FutureTask; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, ExecutionException {
    Date begin = new Date();
    Calculate calculate = new Calculate();
    int c = 0;

    //异步计算
    int two = 0;
    CallableDemo cDemo = new CallableDemo();
    cDemo.setCalculate(calculate);
    FutureTask<Integer> fTask = new FutureTask<>(cDemo);
    new Thread(fTask, "有返回值的线程").start();
    int one = calculate.calOne();
    two = fTask.get();

    //求和
    c = one + two;
    Date end = new Date();
    System.out.println("计算结果:" + c);
    long aaa = end.getTime() - begin.getTime();
    System.out.println("计算耗时:" + aaa);
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:22,代码来源:FutureTaskDemo.java

示例11: getArrowRender

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Override
public TimeGraphArrowRender getArrowRender(TimeGraphTreeRender treeRender, TimeRange timeRange, FutureTask<?> task) {
    TimeGraphArrowSeries series = getArrowSeries();
    List<TimeGraphTreeElement> treeElems = treeRender.getAllTreeElements();

    /* Draw 2 arrows total */
    TimeGraphEvent startEvent = new TimeGraphEvent(ts(timeRange, 0.3), treeElems.get(6));
    TimeGraphEvent endEvent = new TimeGraphEvent(ts(timeRange, 0.8), treeElems.get(4));
    TimeGraphArrow arrow1 = new TimeGraphArrow(startEvent, endEvent, series);

    startEvent = new TimeGraphEvent(ts(timeRange, 0.5), treeElems.get(10));
    endEvent = new TimeGraphEvent(ts(timeRange, 0.6), treeElems.get(7));
    TimeGraphArrow arrow2 = new TimeGraphArrow(startEvent, endEvent, series);

    List<TimeGraphArrow> arrows = ImmutableList.of(arrow1, arrow2);
    return new TimeGraphArrowRender(timeRange, arrows);
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:18,代码来源:TestModelArrowProvider2.java

示例12: getStateRender

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Override
public TimeGraphStateRender getStateRender(TimeGraphTreeElement treeElement,
        TimeRange timeRange, long resolution, FutureTask<?> task) {

    int entryIndex = Integer.valueOf(treeElement.getName().substring(TestModelProvider.ENTRY_NAME_PREFIX.length()));
    long stateLength = entryIndex * DURATION_FACTOR;

    List<TimeGraphStateInterval> intervals = LongStream.iterate(timeRange.getStartTime(), i -> i + stateLength)
            .limit((timeRange.getDuration() / stateLength) + 1)
            .mapToObj(startTime -> {
                long endTime = startTime + stateLength - 1;
                StateDefinition stateDef = getNextStateDef();
                return new BasicTimeGraphStateInterval(startTime, endTime, treeElement, stateDef, stateDef.getName(), Collections.emptyMap());
            })
            .collect(Collectors.toList());

    return new TimeGraphStateRender(timeRange, treeElement, intervals);
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:19,代码来源:TestModelStateProvider.java

示例13: testGet_NegativeInfinityTimeout

import java.util.concurrent.FutureTask; //导入依赖的package包/类
/**
 * timed get with most negative timeout works correctly (i.e. no
 * underflow bug)
 */
public void testGet_NegativeInfinityTimeout() throws Exception {
    final ExecutorService pool = Executors.newFixedThreadPool(10);
    final Runnable nop = new Runnable() { public void run() {}};
    final FutureTask<Void> task = new FutureTask<>(nop, null);
    final List<Future<?>> futures = new ArrayList<>();
    Runnable r = new Runnable() { public void run() {
        for (long timeout : new long[] { 0L, -1L, Long.MIN_VALUE }) {
            try {
                task.get(timeout, NANOSECONDS);
                shouldThrow();
            } catch (TimeoutException success) {
            } catch (Throwable fail) {threadUnexpectedException(fail);}}}};
    for (int i = 0; i < 10; i++)
        futures.add(pool.submit(r));
    try {
        joinPool(pool);
        for (Future<?> future : futures)
            checkCompletedNormally(future, null);
    } finally {
        task.run();         // last resort to help terminate
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:FutureTaskTest.java

示例14: paintArrowsOfProvider

import java.util.concurrent.FutureTask; //导入依赖的package包/类
private void paintArrowsOfProvider(TimeGraphTreeRender treeRender, TimeRange timeRange,
        TimeGraphModelArrowProvider arrowProvider, @Nullable FutureTask<?> task) {
    ArrowConfig config = fArrowProvidersConfig.get(arrowProvider);
    if (config == null) {
        /* Should not happen... */
        return;
    }

    TimeGraphArrowRender arrowRender = arrowProvider.getArrowRender(treeRender, timeRange, task);
    Collection<Arrow> arrows = prepareArrows(treeRender, arrowRender, config.getStroke());

    Platform.runLater(() -> {
        config.getGroup().getChildren().clear();
        config.getGroup().getChildren().addAll(arrows);
    });
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:17,代码来源:TimeGraphArrowLayer.java

示例15: getArrowRender

import java.util.concurrent.FutureTask; //导入依赖的package包/类
@Override
public TimeGraphArrowRender getArrowRender(TimeGraphTreeRender treeRender, TimeRange timeRange, @Nullable FutureTask<?> task) {
    TimeGraphArrowSeries series = getArrowSeries();
    List<TimeGraphTreeElement> treeElems = treeRender.getAllTreeElements();

    /* Draw 2 arrows total */
    TimeGraphEvent startEvent = new TimeGraphEvent(ts(timeRange, 0.3), treeElems.get(6));
    TimeGraphEvent endEvent = new TimeGraphEvent(ts(timeRange, 0.8), treeElems.get(4));
    TimeGraphArrow arrow1 = new TimeGraphArrow(startEvent, endEvent, series);

    startEvent = new TimeGraphEvent(ts(timeRange, 0.5), treeElems.get(10));
    endEvent = new TimeGraphEvent(ts(timeRange, 0.6), treeElems.get(7));
    TimeGraphArrow arrow2 = new TimeGraphArrow(startEvent, endEvent, series);

    List<TimeGraphArrow> arrows = ImmutableList.of(arrow1, arrow2);
    return new TimeGraphArrowRender(timeRange, arrows);
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:18,代码来源:StubModelArrowProvider2.java


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