List of usage examples for java.util.concurrent ThreadLocalRandom current
public static ThreadLocalRandom current()
From source file:io.prestosql.operator.aggregation.AbstractTestApproximateCountDistinct.java
@Test(dataProvider = "provideStandardErrors") public void testMultiplePositionsPartial(double maxStandardError) { for (int i = 0; i < 100; ++i) { int uniques = ThreadLocalRandom.current().nextInt(getUniqueValuesCount()) + 1; List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5)); assertEquals(estimateCountPartial(values, maxStandardError), estimateGroupByCount(values, maxStandardError)); }/*from w ww .j av a2 s .co m*/ }
From source file:com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand.java
private static void showRandomFailureMessage() { if (ThreadLocalRandom.current().nextInt(0, 100) < 5) { int index = ThreadLocalRandom.current().nextInt(0, failureMessages.length); String message = failureMessages[index]; AnsiUi.failure(message);// w w w . j a va2s. com } }
From source file:org.apache.druid.indexing.kafka.test.TestBroker.java
public Map<String, String> consumerProperties() { final Map<String, String> props = Maps.newHashMap(); props.put("bootstrap.servers", StringUtils.format("localhost:%d", getPort())); props.put("key.deserializer", ByteArrayDeserializer.class.getName()); props.put("value.deserializer", ByteArrayDeserializer.class.getName()); props.put("group.id", String.valueOf(ThreadLocalRandom.current().nextInt())); props.put("auto.offset.reset", "earliest"); return props; }
From source file:com.facebook.presto.operator.aggregation.BootstrappedAggregation.java
@Override public GroupedAccumulator createGroupedAggregation(Optional<Integer> maskChannel, Optional<Integer> sampleWeightChannel, double confidence, int... argumentChannels) { checkArgument(sampleWeightChannel.isPresent(), "sample weight must be present for bootstrapping"); return createDeterministicGroupedAggregation(maskChannel, sampleWeightChannel.get(), confidence, ThreadLocalRandom.current().nextLong(), argumentChannels); }
From source file:org.wso2.carbon.analytics.data.commons.test.AnalyticsRecordStoreTest.java
private List<Record> generateRecordsForUpdate(List<Record> recordsIn) { List<Record> result = new ArrayList<>(); int randInt = ThreadLocalRandom.current().nextInt(0, 65536); Map<String, Object> values; for (Record recordIn : recordsIn) { values = new HashMap<>(); values.put("server_name", "ESB-" + recordIn.getId()); values.put("ip", "192.168.0." + (recordIn.getTimestamp() % 256)); values.put("tenant", randInt); values.put("change_index", randInt + 0.3454452); result.add(new Record(recordIn.getId(), recordIn.getTableName(), values, System.currentTimeMillis())); }/*from w w w . ja v a 2 s .c o m*/ return result; }
From source file:com.adaptris.core.services.splitter.ServiceWorkerPool.java
/** * /* w ww .j av a 2 s. com*/ * @deprecated since 3.8.3 switch to commons-pool2 and {@link createCommonsObjectPool()} instead. */ @Deprecated @Removal(version = "3.9.0", message = "use commons-pool2 + createCommonsObjectPool()") public org.apache.commons.pool.impl.GenericObjectPool<Worker> createObjectPool() throws CoreException { logDeprecationWarning(); org.apache.commons.pool.impl.GenericObjectPool<Worker> pool = new org.apache.commons.pool.impl.GenericObjectPool( new LegacyCommonsPoolWorkerFactory()); pool.setMaxActive(maxThreads); pool.setMinIdle(maxThreads); pool.setMaxIdle(maxThreads); pool.setMaxWait(-1L); pool.setWhenExhaustedAction(org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMinEvictableIdleTimeMillis(EVICT_RUN); pool.setTimeBetweenEvictionRunsMillis(EVICT_RUN + ThreadLocalRandom.current().nextLong(EVICT_RUN)); return pool; }
From source file:org.apache.hadoop.hbase.client.TestAsyncGetMultiThread.java
private void run(AtomicBoolean stop) throws InterruptedException, ExecutionException { while (!stop.get()) { int i = ThreadLocalRandom.current().nextInt(COUNT); assertEquals(i, Bytes.toInt(CONN.getRawTable(TABLE_NAME) .get(new Get(Bytes.toBytes(String.format("%03d", i)))).get().getValue(FAMILY, QUALIFIER))); }/*from w w w . j av a 2 s. c o m*/ }
From source file:com.facebook.presto.operator.aggregation.BootstrappedAggregation.java
@Override public GroupedAccumulator createGroupedIntermediateAggregation(double confidence) { return createDeterministicGroupedIntermediateAggregation(confidence, ThreadLocalRandom.current().nextLong()); }
From source file:org.apache.sysml.utils.lite.BuildLiteExecution.java
public static void jmlcUnivariateStatistics() throws Exception { Connection conn = getConfiguredConnection(); String dml = conn.readScript("scripts/algorithms/Univar-Stats.dml"); Map<String, String> m = new HashMap<>(); m.put("$CONSOLE_OUTPUT", "TRUE"); PreparedScript script = conn.prepareScript(dml, m, new String[] { "A", "K" }, new String[] { "baseStats" }, false);/*from ww w . j ava 2s .c o m*/ double[][] data = new double[100][4]; for (int i = 0; i < 100; i++) { int one = ThreadLocalRandom.current().nextInt(0, 101); int two = ThreadLocalRandom.current().nextInt(0, 101); int three = ThreadLocalRandom.current().nextInt(0, 101); int four = ThreadLocalRandom.current().nextInt(1, 3); double[] row = new double[] { one, two, three, four }; data[i] = row; } log.debug(displayMatrix(data)); double[][] types = matrix(1, 4, new double[] { 1, 1, 1, 2 }); script.setMatrix("A", data); script.setMatrix("K", types); double[][] baseStats = script.executeScript().getMatrix("baseStats"); log.debug(displayMatrix(baseStats)); conn.close(); }
From source file:org.apache.hadoop.hbase.util.MultiHConnection.java
/** * Randomly pick a connection and process the batch of actions for a given table * @param actions the actions// ww w .j a v a2 s . co m * @param tableName table name * @param results the results array * @param callback * @throws IOException */ @SuppressWarnings("deprecation") public <R> void processBatchCallback(List<? extends Row> actions, TableName tableName, Object[] results, Batch.Callback<R> callback) throws IOException { // Currently used by RegionStateStore // A deprecated method is used as multiple threads accessing RegionStateStore do a single put // and htable is not thread safe. Alternative would be to create an Htable instance for each // put but that is not very efficient. // See HBASE-11610 for more details. try { hConnections[ThreadLocalRandom.current().nextInt(noOfConnections)].processBatchCallback(actions, tableName, this.batchPool, results, callback); } catch (InterruptedException e) { throw new InterruptedIOException(e.getMessage()); } }