Example usage for java.util.concurrent ThreadLocalRandom current

List of usage examples for java.util.concurrent ThreadLocalRandom current

Introduction

In this page you can find the example usage for java.util.concurrent ThreadLocalRandom current.

Prototype

public static ThreadLocalRandom current() 

Source Link

Document

Returns the current thread's ThreadLocalRandom .

Usage

From source file:com.adaptris.core.services.splitter.ServiceWorkerPool.java

public GenericObjectPool<Worker> createCommonsObjectPool() throws CoreException {
    GenericObjectPool<Worker> pool = new GenericObjectPool<>(new WorkerFactory());
    // Make the pool the same size as the thread pool
    pool.setMaxTotal(maxThreads);/*from w w  w. ja v a  2s  .c om*/
    pool.setMinIdle(maxThreads);
    pool.setMaxIdle(maxThreads);
    pool.setMaxWaitMillis(-1L);
    pool.setBlockWhenExhausted(true);
    pool.setSoftMinEvictableIdleTimeMillis(EVICT_RUN);
    pool.setTimeBetweenEvictionRunsMillis(EVICT_RUN + ThreadLocalRandom.current().nextLong(EVICT_RUN));
    return pool;
}

From source file:com.facebook.presto.operator.aggregation.AbstractTestApproximateCountDistinct.java

@Test(dataProvider = "provideStandardErrors")
public void testMultiplePositions(double maxStandardError) throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < 500; ++i) {
        int uniques = ThreadLocalRandom.current().nextInt(20000) + 1;

        List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

        long actual = estimateGroupByCount(values, maxStandardError);
        double error = (actual - uniques) * 1.0 / uniques;

        stats.addValue(error);/*w w w .  j  a v a2  s  .c  o  m*/
    }

    assertLessThan(stats.getMean(), 1.0e-2);
    assertLessThan(Math.abs(stats.getStandardDeviation() - maxStandardError), 1.0e-2);
}

From source file:com.here.account.auth.OAuth1Signer.java

/**
 * The source of entropy for OAuth1.0 nonce values.
 * File bytes with entropy for OAuth1.0 nonce values.
 * Note the OAuth1.0 spec specifically tells us we do not need to use a SecureRandom 
 * number generator.//from w w w  .  j  a  v  a  2 s.  c  o m
 * 
 * @param bytes the byte array in which to stick the nonce value
 */
protected void nextBytes(byte[] bytes) {
    ThreadLocalRandom.current().nextBytes(bytes);
    ;
}

From source file:org.apache.james.modules.rabbitmq.RabbitMQModule.java

@Override
protected void configure() {
    bind(Clock.class).toInstance(Clock.systemUTC());
    bind(ThreadLocalRandom.class).toInstance(ThreadLocalRandom.current());

    bind(EnqueuedMailsDAO.class).in(Scopes.SINGLETON);
    bind(DeletedMailsDAO.class).in(Scopes.SINGLETON);
    bind(BrowseStartDAO.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueBrowser.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueMailDelete.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueMailStore.class).in(Scopes.SINGLETON);

    bind(SimpleChannelPool.class).in(Scopes.SINGLETON);
    bind(RabbitMQChannelPool.class).to(SimpleChannelPool.class);

    Multibinder<CassandraModule> cassandraModuleBinder = Multibinder.newSetBinder(binder(),
            CassandraModule.class);
    cassandraModuleBinder.addBinding().toInstance(CassandraMailQueueViewModule.MODULE);

    bind(EventsourcingConfigurationManagement.class).in(Scopes.SINGLETON);
    @SuppressWarnings("rawtypes")
    Multibinder<EventDTOModule> eventDTOModuleBinder = Multibinder.newSetBinder(binder(), EventDTOModule.class);
    eventDTOModuleBinder.addBinding()/* w w  w . ja  v  a2s .com*/
            .toInstance(CassandraMailQueueViewConfigurationModule.MAIL_QUEUE_VIEW_CONFIGURATION);
}

From source file:io.prestosql.operator.aggregation.AbstractTestApproximateCountDistinct.java

@Test(dataProvider = "provideStandardErrors")
public void testMultiplePositions(double maxStandardError) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < 500; ++i) {
        int uniques = ThreadLocalRandom.current().nextInt(getUniqueValuesCount()) + 1;

        List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

        long actual = estimateGroupByCount(values, maxStandardError);
        double error = (actual - uniques) * 1.0 / uniques;

        stats.addValue(error);/*from  w  ww.java  2s  .  c om*/
    }

    assertLessThan(stats.getMean(), 1.0e-2);
    assertLessThan(stats.getStandardDeviation(), 1.0e-2 + maxStandardError);
}

From source file:com.facebook.presto.operator.aggregation.BootstrappedAggregation.java

@Override
public Accumulator createAggregation(Optional<Integer> maskChannel, Optional<Integer> sampleWeightChannel,
        double confidence, int... argumentChannels) {
    checkArgument(sampleWeightChannel.isPresent(), "sample weight must be present for bootstrapping");
    return createDeterministicAggregation(maskChannel, sampleWeightChannel.get(), confidence,
            ThreadLocalRandom.current().nextLong(), argumentChannels);
}

From source file:com.appdevper.mediaplayer.util.QueueHelper.java

/**
 * Create a random queue.//from  ww  w  . jav  a2s  .  c  o  m
 *
 * @param musicProvider the provider used for fetching music.
 * @return list containing {@link MediaSession.QueueItem}'s
 */
public static List<MediaSessionCompat.QueueItem> getRandomQueue(MusicProvider musicProvider) {
    List<MediaMetadataCompat> result = new ArrayList<>();

    for (String genre : musicProvider.getGenres()) {
        Iterable<MediaMetadataCompat> tracks = musicProvider.getMusicsByGenre(genre);
        for (MediaMetadataCompat track : tracks) {
            if (ThreadLocalRandom.current().nextBoolean()) {
                result.add(track);
            }
        }
    }
    LogHelper.d(TAG, "getRandomQueue: result.size=", result.size());

    Collections.shuffle(result);

    return convertToQueue(result, MediaIDHelper.MEDIA_ID_MUSICS_BY_SEARCH, "random");
}

From source file:cf.spring.CfComponentConfiguration.java

@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    final MultiValueMap<String, Object> attributes = importMetadata
            .getAllAnnotationAttributes(CfComponent.class.getName());
    type = evaluate(attributes, "type");
    index = Integer.valueOf(evaluate(attributes, "index"));
    uuid = evaluate(attributes, "uuid");
    if (StringUtils.isEmpty(uuid)) {
        uuid = UUID.randomUUID().toString();
    }//w w  w  .  j  a va2 s . c o  m
    host = evaluate(attributes, "host");
    port = Integer.valueOf(evaluate(attributes, "port"));
    username = evaluate(attributes, "username");
    password = evaluate(attributes, "password");
    if (StringUtils.isEmpty(password)) {
        password = new BigInteger(256, ThreadLocalRandom.current()).toString(32);
    }
}

From source file:io.hops.hopsworks.common.dao.jupyter.JupyterSettingsFacade.java

public JupyterSettings findByProjectUser(int projectId, String email) {

    JupyterSettingsPK pk = new JupyterSettingsPK(projectId, email);
    JupyterSettings js = null;/*from w w w .j a  v a  2  s.c om*/
    js = em.find(JupyterSettings.class, pk);
    if (js == null) {
        String secret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt()));
        js = new JupyterSettings(pk);
        js.setSecret(secret);
        js.setMode("sparkDynamic");
        persist(js);
    }
    return js;

}

From source file:com.adaptris.util.PseudoRandomIdGenerator.java

Random random() {
    return useSecureRandom() ? SECURE_RAND : ThreadLocalRandom.current();
}