Examples of ThreadLocalRandom


Examples of java.util.concurrent.ThreadLocalRandom

    {
        int count = state.rowGen.count(index);
        List<ByteBuffer> src = state.settings.columns.names;
        if (count == src.size())
            return src;
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        List<ByteBuffer> r = new ArrayList<>();
        int c = 0, o = 0;
        while (c < count && count + o < src.size())
        {
            int leeway = src.size() - (count + o);
            int spreadover = count - c;
            o += Math.round(rnd.nextDouble() * (leeway / (double) spreadover));
            r.add(src.get(o + c++));
        }
        while (c < count)
            r.add(src.get(o + c++));
        return r;
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

    }

    @Setup
    public void setup() throws IOException
    {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        int[] randomRunLength = range(this.randomRunLength);
        int[] duplicateLookback = range(this.duplicateLookback);
        rawBytes = new byte[uniquePages][pageSize];
        lz4Bytes = new byte[uniquePages][];
        snappyBytes = new byte[uniquePages][];
        byte[][] runs = new byte[duplicateLookback[1] - duplicateLookback[0]][];
        for (int i = 0 ; i < rawBytes.length ; i++)
        {
            byte[] trg = rawBytes[0];
            int runCount = 0;
            int byteCount = 0;
            while (byteCount < trg.length)
            {
                byte[] nextRun;
                if (runCount == 0 || random.nextDouble() < this.randomRatio)
                {
                    nextRun = new byte[random.nextInt(randomRunLength[0], randomRunLength[1])];
                    random.nextBytes(nextRun );
                    runs[runCount % runs.length] = nextRun;
                    runCount++;
                }
                else
                {
                    int index = runCount < duplicateLookback[1]
                            ? random.nextInt(runCount)
                            : (runCount - random.nextInt(duplicateLookback[0], duplicateLookback[1]));
                    nextRun = runs[index % runs.length];
                }
                System.arraycopy(nextRun, 0, trg, byteCount, Math.min(nextRun.length, trg.length - byteCount));
                byteCount += nextRun.length;
            }
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

    }

    @Test
    public void testAddEdgeALot() {
        MatrixGraph graph = new MatrixGraph(17);
        ThreadLocalRandom random = ThreadLocalRandom.current();
        IntStream.range(0, 1000).forEach(index -> {
            int i = random.nextInt(17);
            int j = random.nextInt(17);
            int value = random.nextInt(10_000) - 5_000;
            graph.addEdge(i, j, value);
            assertTrue(graph.hasEdge(i, j));
            assertEquals(value, graph.getWeight(i, j));
        });
    }
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

        {
            MODIFY.execute(new Runnable()
            {
                public void run()
                {
                    ThreadLocalRandom random = ThreadLocalRandom.current();
                    for (int i = 0 ; i < perThreadTrees ; i++)
                    {
                        Object[] tree = randomTree(10000, random);
                        for (int j = 0 ; j < perTreeSelections ; j++)
                        {
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

        int count = (int) columnCount.next();
        int totalCount = settings.columns.names.size();
        if (count == settings.columns.names.size())
            return new ColumnSelection(null, 0, count);
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int[] indices = new int[count];
        int c = 0, o = 0;
        while (c < count && count + o < totalCount)
        {
            int leeway = totalCount - (count + o);
            int spreadover = count - c;
            o += Math.round(rnd.nextDouble() * (leeway / (double) spreadover));
            indices[c] = o + c;
            c++;
        }
        while (c < count)
        {
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

        int count = (int) columnCount.next();
        int totalCount = settings.columns.names.size();
        if (count == settings.columns.names.size())
            return new ColumnSelection(null, 0, count);
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int[] indices = new int[count];
        int c = 0, o = 0;
        while (c < count && count + o < totalCount)
        {
            int leeway = totalCount - (count + o);
            int spreadover = count - c;
            o += Math.round(rnd.nextDouble() * (leeway / (double) spreadover));
            indices[c] = o + c;
            c++;
        }
        while (c < count)
        {
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

        final ScheduledExecutorService sched;

        TestOrdering(ExecutorService exec, ScheduledExecutorService sched)
        {
            this.sched = sched;
            final ThreadLocalRandom rnd = ThreadLocalRandom.current();
            for (int i = 0 ; i < waitNanos.length ; i++)
                waitNanos[i] = rnd.nextInt(5000);
            for (int i = 0 ; i < PRODUCERS / CONSUMERS ; i++)
                exec.execute(new Producer());
            exec.execute(this);
        }
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

     */
    private Message awaitMatch(Node s, Node pred, Message e, boolean timed, long nanos) throws SuspendExecution {
        long lastTime = timed ? System.nanoTime() : 0L;
        Strand w = Strand.currentStrand();
        int spins = (w instanceof Fiber ? 0 : -1); // no spins in fiber; otherwise, initialized after first item and cancel checks
        ThreadLocalRandom randomYields = null; // bound if needed
       
        if(spins == 0)
            s.waiter = w;
       
        for (;;) {
            Object item = s.item;

            if (item == CHANNEL_CLOSED)
                setReceiveClosed();

            if (item != e) {                  // matched
                // assert item != s;
                s.forgetContents();           // avoid garbage
                return this.<Message>cast(item);
            }
            if ((w.isInterrupted() || (timed && nanos <= 0))
                    && s.casItem(e, s)) {        // cancel
                unsplice(pred, s);
                return e;
            }

            if (spins < 0) {                  // establish spins at/near front
                if ((spins = spinsFor(pred, s.isData)) > 0)
                    randomYields = ThreadLocalRandom.current();
            } else if (spins > 0) {             // spin
                --spins;
                if (randomYields.nextInt(CHAINED_SPINS) == 0)
                    Strand.yield();           // occasionally yield
            } else if (s.waiter == null) {
                s.waiter = w;                 // request unpark then recheck
            } else if (timed) {
                long now = System.nanoTime();
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

     */
    private Message awaitMatch(Node s, Node pred, Message e, boolean timed, long nanos) throws SuspendExecution {
        long lastTime = timed ? System.nanoTime() : 0L;
        Strand w = Strand.currentStrand();
        int spins = (w.isFiber() ? 0 : -1); // no spins in fiber; otherwise, initialized after first item and cancel checks
        ThreadLocalRandom randomYields = null; // bound if needed

        if (spins == 0)
            requestUnpark(s, w);

        for (;;) {
            Object item = s.item;

            if (item == CHANNEL_CLOSED)
                setReceiveClosed();

            if (item != e) {                  // matched
                // assert item != s;
                s.forgetContents();           // avoid garbage
                return this.<Message>cast(item);
            }
            if ((w.isInterrupted() || (timed && nanos <= 0))
                    && s.casItem(e, s)) {     // cancel
                unsplice(pred, s);
                return e;
            }

            if (spins < 0) {                  // establish spins at/near front
                if ((spins = spinsFor(pred, s.isData)) > 0)
                    randomYields = ThreadLocalRandom.current();
            } else if (spins > 0) {           // spin
                --spins;
                if (randomYields.nextInt(CHAINED_SPINS) == 0)
                    Strand.yield();           // occasionally yield
            } else if (s.waiter == null) {
                requestUnpark(s, w);          // request unpark then recheck
            } else if (timed) {
                long now = System.nanoTime();
View Full Code Here

Examples of java.util.concurrent.ThreadLocalRandom

        for (int t = 0; t < NUM_PRODUCERS; t++) {
            producers[t] = new Thread(new Runnable() {
                @Override
                public void run() {
                    final ThreadLocalRandom rand = ThreadLocalRandom.current();
                    int i = REPETITIONS / NUM_PRODUCERS;
                    do {
                        while (!queue.offer(DelayedValue.instance(SEQUENCED, TEST_VALUE, rand.nextInt(0, 11))))
                            Thread.yield();
                    } while (0 != --i);
                }
            });
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.