Search in sources :

Example 41 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.

the class ThreadLocalRandomTest method testUnsizedDoublesCountSeq.

/**
     * A sequential unsized stream of doubles generates at least 100 values
     */
public void testUnsizedDoublesCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 42 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.

the class ThreadLocalRandomTest method testUnsizedIntsCount.

/**
     * A parallel unsized stream of ints generates at least 100 values
     */
public void testUnsizedIntsCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.ints().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 43 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.

the class ThreadLocalRandomTest method testUnsizedDoublesCount.

/**
     * A parallel unsized stream of doubles generates at least 100 values
     */
public void testUnsizedDoublesCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.doubles().limit(size).parallel().forEach(x -> {
        counter.increment();
    });
    assertEquals(counter.sum(), size);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 44 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project gerrit by GerritCodeReview.

the class SmtpEmailSender method generateMultipartBoundary.

public static String generateMultipartBoundary(String textBody, String htmlBody) throws EmailException {
    byte[] bytes = new byte[8];
    ThreadLocalRandom rng = ThreadLocalRandom.current();
    // suffice, something is seriously wrong.
    for (int i = 0; i < 2; i++) {
        rng.nextBytes(bytes);
        String boundary = BaseEncoding.base64().encode(bytes);
        String encBoundary = "--" + boundary;
        if (textBody.contains(encBoundary) || htmlBody.contains(encBoundary)) {
            continue;
        }
        return boundary;
    }
    throw new EmailException("Gave up generating unique MIME boundary");
}
Also used : EmailException(com.google.gerrit.common.errors.EmailException) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 45 with ThreadLocalRandom

use of java.util.concurrent.ThreadLocalRandom in project Glowstone by GlowstoneMC.

the class BlockOre method getDrops.

public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    int count = minCount;
    if (maxCount > minCount) {
        count += random.nextInt(maxCount - minCount);
    }
    ItemStack stack = new ItemStack(dropType, count, (short) data);
    if (tool == null) {
        return Collections.unmodifiableList(Arrays.asList(stack));
    }
    Collection<ItemStack> drops = super.getDrops(block, tool);
    if (drops.size() == 0) {
        return drops;
    }
    if (tool.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
        stack.setAmount(count * getMultiplicator(random, tool.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)));
    }
    return Collections.unmodifiableList(Arrays.asList(stack));
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)236 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)73 Ignite (org.apache.ignite.Ignite)65 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)53 IgniteCache (org.apache.ignite.IgniteCache)44 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 IgniteException (org.apache.ignite.IgniteException)27 Transaction (org.apache.ignite.transactions.Transaction)26 CacheException (javax.cache.CacheException)24 HashMap (java.util.HashMap)22 Map (java.util.Map)20 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)17 LongAdder (java.util.concurrent.atomic.LongAdder)15 TreeMap (java.util.TreeMap)14 IgniteTransactions (org.apache.ignite.IgniteTransactions)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Callable (java.util.concurrent.Callable)11 CountDownLatch (java.util.concurrent.CountDownLatch)11