Package java.util.concurrent

Examples of java.util.concurrent.ThreadLocalRandom.nextInt()


                    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


                }
                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

    @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

    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

        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

        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

            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

            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

                @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

    private static int[] randomIntArray(int n) {
        final ThreadLocalRandom random = ThreadLocalRandom.current();
        final int[] a = new int[n];
        for (int i = 1; i < n; i++) {
            int x = random.nextInt(i);
            a[i] = a[x];
            a[x] = i;
        }
        return a;
    }
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.