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


Java ThreadLocalRandom.nextSecondarySeed方法代码示例

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


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

示例1: findNonEmptyStealQueue

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Returns a (probably) non-empty steal queue, if one is found
 * during a scan, else null.  This method must be retried by
 * caller if, by the time it tries to use the queue, it is empty.
 */
private WorkQueue findNonEmptyStealQueue() {
    WorkQueue[] ws; int m;  // one-shot version of scan loop
    int r = ThreadLocalRandom.nextSecondarySeed();
    if ((ws = workQueues) != null && (m = ws.length - 1) >= 0) {
        for (int origin = r & m, k = origin, oldSum = 0, checkSum = 0;;) {
            WorkQueue q; int b;
            if ((q = ws[k]) != null) {
                if ((b = q.base) - q.top < 0)
                    return q;
                checkSum += b;
            }
            if ((k = (k + 1) & m) == origin) {
                if (oldSum == (oldSum = checkSum))
                    break;
                checkSum = 0;
            }
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ForkJoinPool.java

示例2: awaitRunStateLock

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Spins and/or blocks until runstate lock is available.  See
 * above for explanation.
 */
private int awaitRunStateLock() {
    Object lock;
    boolean wasInterrupted = false;
    for (int spins = SPINS, r = 0, rs, ns;;) {
        if (((rs = runState) & RSLOCK) == 0) {
            if (U.compareAndSwapInt(this, RUNSTATE, rs, ns = rs | RSLOCK)) {
                if (wasInterrupted) {
                    try {
                        Thread.currentThread().interrupt();
                    } catch (SecurityException ignore) {
                    }
                }
                return ns;
            }
        }
        else if (r == 0)
            r = ThreadLocalRandom.nextSecondarySeed();
        else if (spins > 0) {
            r ^= r << 6; r ^= r >>> 21; r ^= r << 7; // xorshift
            if (r >= 0)
                --spins;
        }
        else if ((rs & STARTED) == 0 || (lock = stealCounter) == null)
            Thread.yield();   // initialization race
        else if (U.compareAndSwapInt(this, RUNSTATE, rs, rs | RSIGNAL)) {
            synchronized (lock) {
                if ((runState & RSIGNAL) != 0) {
                    try {
                        lock.wait();
                    } catch (InterruptedException ie) {
                        if (!(Thread.currentThread() instanceof
                              ForkJoinWorkerThread))
                            wasInterrupted = true;
                    }
                }
                else
                    lock.notifyAll();
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:ForkJoinPool.java

示例3: waitingGet

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