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


Java ForkJoinPool.managedBlock方法代码示例

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


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

示例1: timedGet

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * Returns raw result after waiting, or null if interrupted, or
 * throws TimeoutException on timeout.
 */
private Object timedGet(long nanos) throws TimeoutException {
    if (Thread.interrupted())
        return null;
    if (nanos <= 0L)
        throw new TimeoutException();
    long d = System.nanoTime() + nanos;
    Signaller q = new Signaller(true, nanos, d == 0L ? 1L : d); // avoid 0
    boolean queued = false;
    Object r;
    // We intentionally don't spin here (as waitingGet does) because
    // the call to nanoTime() above acts much like a spin.
    while ((r = result) == null) {
        if (!queued)
            queued = tryPushStack(q);
        else if (q.interruptControl < 0 || q.nanos <= 0L) {
            q.thread = null;
            cleanStack();
            if (q.interruptControl < 0)
                return null;
            throw new TimeoutException();
        }
        else if (q.thread != null && result == null) {
            try {
                ForkJoinPool.managedBlock(q);
            } catch (InterruptedException ie) {
                q.interruptControl = -1;
            }
        }
    }
    if (q.interruptControl < 0)
        r = null;
    q.thread = null;
    postComplete();
    return r;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:CompletableFuture.java

示例2: waitForInternal

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * Wait for the process to exit by calling {@code waitFor}.
 * If the thread is interrupted, remember the interrupted state to
 * be restored before returning. Use ForkJoinPool.ManagedBlocker
 * so that the number of workers in case ForkJoinPool is used is
 * compensated when the thread blocks in waitFor().
 *
 * @return the Process
 */
private Process waitForInternal() {
    boolean interrupted = false;
    while (true) {
        try {
            ForkJoinPool.managedBlock(new ForkJoinPool.ManagedBlocker() {
                @Override
                public boolean block() throws InterruptedException {
                    waitFor();
                    return true;
                }

                @Override
                public boolean isReleasable() {
                    return !isAlive();
                }
            });
            break;
        } catch (InterruptedException x) {
            interrupted = true;
        }
    }
    if (interrupted) {
        Thread.currentThread().interrupt();
    }
    return this;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:Process.java

示例3: waitingGet

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * Returns raw result after waiting, or null if interruptible and
 * interrupted.
 */
private Object waitingGet(boolean interruptible) {
    Signaller q = null;
    boolean queued = false;
    int spins = -1;
    Object r;
    while ((r = result) == null) {
        if (spins < 0)
            spins = (Runtime.getRuntime().availableProcessors() > 1) ?
                1 << 8 : 0; // Use brief spin-wait on multiprocessors
        else if (spins > 0) {
            if (ThreadLocalRandom.nextSecondarySeed() >= 0)
                --spins;
        }
        else if (q == null)
            q = new Signaller(interruptible, 0L, 0L);
        else if (!queued)
            queued = tryPushStack(q);
        else if (interruptible && q.interruptControl < 0) {
            q.thread = null;
            cleanStack();
            return null;
        }
        else if (q.thread != null && result == null) {
            try {
                ForkJoinPool.managedBlock(q);
            } catch (InterruptedException ie) {
                q.interruptControl = -1;
            }
        }
    }
    if (q != null) {
        q.thread = null;
        if (q.interruptControl < 0) {
            if (interruptible)
                r = null; // report interruption
            else
                Thread.currentThread().interrupt();
        }
    }
    postComplete();
    return r;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:CompletableFuture.java


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