Package java.util.concurrent

Examples of java.util.concurrent.ThreadLocalRandom


    {
      public void writeData(Attributes attributes)
      {
        try
        {
          final ThreadLocalRandom random = ThreadLocalRandom.current();
          DataSource dataSource = WicketApplication.get().getDataSource();
          World[] worlds = new World[queries];
          try (Connection connection = dataSource.getConnection())
          {
            try (PreparedStatement statement = connection.prepareStatement(
                       "SELECT * FROM World WHERE id = ?",
                       ResultSet.TYPE_FORWARD_ONLY,
                       ResultSet.CONCUR_READ_ONLY))
            {
              for (int i = 0; i < queries; i++)
              {
                  statement.setInt(1, random.nextInt(DB_ROWS) + 1);
                  try (ResultSet resultSet = statement.executeQuery())
                  {
                      resultSet.next();
                      worlds[i] = new World(
                              resultSet.getInt("id"),
View Full Code Here


    response.setWriteCallback(new WriteCallback() {
      public void writeData(Attributes attributes)
      {
        try
        {
          final ThreadLocalRandom random = ThreadLocalRandom.current();
          DataSource dataSource = WicketApplication.get().getDataSource();

          World[] worlds = new World[queries];
          try (Connection connection = dataSource.getConnection();
               PreparedStatement query = connection.prepareStatement(
                       "SELECT * FROM World WHERE id = ?",
                       ResultSet.TYPE_FORWARD_ONLY,
                       ResultSet.CONCUR_READ_ONLY);
               PreparedStatement update = connection.prepareStatement(
                       "UPDATE World SET randomNumber = ? WHERE id= ?"))
          {
            for (int i = 0; i < queries; i++)
            {
              query.setInt(1, random.nextInt(DB_ROWS) + 1);
              World world;
              try (ResultSet resultSet = query.executeQuery())
              {
                resultSet.next();
                world = new World(
                    resultSet.getInt("id"),
                    resultSet.getInt("randomNumber"));
              }
              world.randomNumber = random.nextInt(DB_ROWS) + 1;
              update.setInt(1, world.randomNumber);
              update.setInt(2, world.id);
              update.executeUpdate();
              worlds[i] = world;
            }
View Full Code Here

    }

    private Set<MeasurementDataNumeric> generateData() {
        Set<MeasurementDataNumeric> data = new HashSet<MeasurementDataNumeric>(batchSize);
        long timestamp = dateTimeService.nowInMillis();
        ThreadLocalRandom random = ThreadLocalRandom.current();

        for (int i = 0; i < batchSize; ++i) {
            data.add(new MeasurementDataNumeric(timestamp, startingScheduleId + i, random.nextDouble()));
        }

        return data;
    }
View Full Code Here

      Collection<Example> examples = input.first();
      FeedforwardParams params = input.second();

      // We can't fix the seed used with ThreadLocalRandom
      // TODO: Is this a serious problem?
      ThreadLocalRandom random = ThreadLocalRandom.current();

      gradW1 = new double[W1.length][W1[0].length];
      gradb1 = new double[b1.length];
      gradW2 = new double[W2.length][W2[0].length];
      gradE = new double[E.length][E[0].length];

      double cost = 0.0;
      double correct = 0.0;

      for (Example ex : examples) {
        List<Integer> feature = ex.getFeature();
        List<Integer> label = ex.getLabel();

        double[] scores = new double[numLabels];
        double[] hidden = new double[config.hiddenSize];
        double[] hidden3 = new double[config.hiddenSize];

        // Run dropout: randomly drop some hidden-layer units. `ls`
        // contains the indices of those units which are still active
        int[] ls = IntStream.range(0, config.hiddenSize)
                            .filter(n -> random.nextDouble() > params.getDropOutProb())
                            .toArray();

        int offset = 0;
        for (int j = 0; j < config.numTokens; ++j) {
          int tok = feature.get(j);
View Full Code Here

        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

    {
        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

    }

    @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

    }

    @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

        {
            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

        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

TOP

Related Classes of java.util.concurrent.ThreadLocalRandom

Copyright © 2018 www.massapicom. 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.