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


Java ThreadLocalRandom.getProbe方法代码示例

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


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

示例1: externalPush

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Tries to add the given task to a submission queue at
 * submitter's current queue. Only the (vastly) most common path
 * is directly handled in this method, while screening for need
 * for externalSubmit.
 *
 * @param task the task. Caller must ensure non-null.
 */
final void externalPush(ForkJoinTask<?> task) {
    WorkQueue[] ws; WorkQueue q; int m;
    int r = ThreadLocalRandom.getProbe();
    int rs = runState;
    if ((ws = workQueues) != null && (m = (ws.length - 1)) >= 0 &&
        (q = ws[m & r & SQMASK]) != null && r != 0 && rs > 0 &&
        U.compareAndSwapInt(q, QLOCK, 0, 1)) {
        ForkJoinTask<?>[] a; int am, n, s;
        if ((a = q.array) != null &&
            (am = a.length - 1) > (n = (s = q.top) - q.base)) {
            int j = ((am & s) << ASHIFT) + ABASE;
            U.putOrderedObject(a, j, task);
            U.putOrderedInt(q, QTOP, s + 1);
            U.putOrderedInt(q, QLOCK, 0);
            if (n <= 1)
                signalWork(ws, q);
            return;
        }
        U.compareAndSwapInt(q, QLOCK, 1, 0);
    }
    externalSubmit(task);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:ForkJoinPool.java

示例2: tryExternalUnpush

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Performs tryUnpush for an external submitter: Finds queue,
 * locks if apparently non-empty, validates upon locking, and
 * adjusts top. Each check can fail but rarely does.
 */
final boolean tryExternalUnpush(ForkJoinTask<?> task) {
    WorkQueue[] ws; WorkQueue w; ForkJoinTask<?>[] a; int m, s;
    int r = ThreadLocalRandom.getProbe();
    if ((ws = workQueues) != null && (m = ws.length - 1) >= 0 &&
        (w = ws[m & r & SQMASK]) != null &&
        (a = w.array) != null && (s = w.top) != w.base) {
        long j = (((a.length - 1) & (s - 1)) << ASHIFT) + ABASE;
        if (U.compareAndSwapInt(w, QLOCK, 0, 1)) {
            if (w.top == s && w.array == a &&
                U.getObject(a, j) == task &&
                U.compareAndSwapObject(a, j, task, null)) {
                U.putOrderedInt(w, QTOP, s - 1);
                U.putOrderedInt(w, QLOCK, 0);
                return true;
            }
            U.compareAndSwapInt(w, QLOCK, 1, 0);
        }
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ForkJoinPool.java

示例3: externalPush

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Tries to add the given task to a submission queue at
 * submitter's current queue. Only the (vastly) most common path
 * is directly handled in this method, while screening for need
 * for externalSubmit.
 *
 * @param task the task. Caller must ensure non-null.
 */
final void externalPush(ForkJoinTask<?> task) {
    WorkQueue[] ws; WorkQueue q; int m;
    int r = ThreadLocalRandom.getProbe();
    int rs = runState;
    if ((ws = workQueues) != null && (m = (ws.length - 1)) >= 0 &&
        (q = ws[m & r & SQMASK]) != null && r != 0 && rs > 0 &&
        U.compareAndSwapInt(q, QLOCK, 0, 1)) {
        ForkJoinTask<?>[] a; int am, n, s;
        if ((a = q.array) != null &&
            (am = a.length - 1) > (n = (s = q.top) - q.base)) {
            int j = ((am & s) << ASHIFT) + ABASE;
            U.putOrderedObject(a, j, task);
            U.putOrderedInt(q, QTOP, s + 1);
            U.putIntVolatile(q, QLOCK, 0);
            if (n <= 1)
                signalWork(ws, q);
            return;
        }
        U.compareAndSwapInt(q, QLOCK, 1, 0);
    }
    externalSubmit(task);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:ForkJoinPool.java

示例4: commonSubmitterQueue

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Returns common pool queue for an external thread.
 */
static WorkQueue commonSubmitterQueue() {
    ForkJoinPool p = common;
    int r = ThreadLocalRandom.getProbe();
    WorkQueue[] ws; int m;
    return (p != null && (ws = p.workQueues) != null &&
            (m = ws.length - 1) >= 0) ?
        ws[m & r & SQMASK] : null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ForkJoinPool.java

示例5: externalHelpComplete

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Performs helpComplete for an external submitter.
 */
final int externalHelpComplete(CountedCompleter<?> task, int maxTasks) {
    WorkQueue[] ws; int n;
    int r = ThreadLocalRandom.getProbe();
    return ((ws = workQueues) == null || (n = ws.length) == 0) ? 0 :
        helpComplete(ws[(n - 1) & r & SQMASK], task, maxTasks);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:ForkJoinPool.java


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