當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadLocalRandom.nextLong方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadLocalRandom.nextLong方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadLocalRandom.nextLong方法的具體用法?Java ThreadLocalRandom.nextLong怎麽用?Java ThreadLocalRandom.nextLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadLocalRandom的用法示例。


在下文中一共展示了ThreadLocalRandom.nextLong方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generator

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
public static String generator(String dbName, String tblName, long beginTime, long endTime)
{
    ConsumerConfig config = ConsumerConfig.INSTANCE();
    String hdfsWarehouse = config.getHDFSWarehouse();
    ThreadLocalRandom tlr = ThreadLocalRandom.current();
    long random = tlr.nextLong();
    return String.format("%s/%s/%s/%s-%s-%d%d%d", hdfsWarehouse, dbName, tblName, dbName, tblName, beginTime, endTime, random);
}
 
開發者ID:dbiir,項目名稱:paraflow,代碼行數:9,代碼來源:FileNameGenerator.java

示例2: submitWork

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
public QueryId submitWork(UserClientConnection connection, RunQuery query) {
  ThreadLocalRandom r = ThreadLocalRandom.current();

  // create a new queryid where the first four bytes are a growing time (each new value comes earlier in sequence).  Last 12 bytes are random.
  long time = (int) (System.currentTimeMillis()/1000);
  long p1 = ((Integer.MAX_VALUE - time) << 32) + r.nextInt();
  long p2 = r.nextLong();
  QueryId id = QueryId.newBuilder().setPart1(p1).setPart2(p2).build();
  incrementer.increment(connection.getSession());
  Foreman foreman = new Foreman(bee, bee.getContext(), connection, id, query);
  bee.addNewForeman(foreman);
  return id;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:14,代碼來源:UserWorker.java

示例3: generateDateTimeValues

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
private List<DateTime> generateDateTimeValues(int size) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    long now = System.currentTimeMillis();
    List<DateTime> temp = new ArrayList<>(size);

    for (int i = 0; i < size; i++) {
        long t1 = random.nextLong(now);
        temp.add(new DateTime(t1));
    }

    return temp;
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:13,代碼來源:DateTimeUtilsTest.java

示例4: testNextLongBoundNonPositive

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
/**
 * nextLong(non-positive) throws IllegalArgumentException
 */
public void testNextLongBoundNonPositive() {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    for (long bound : new long[] { 0L, -17L, Long.MIN_VALUE }) {
        try {
            rnd.nextLong(bound);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:ThreadLocalRandomTest.java

示例5: testNextLongBadBounds

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
/**
 * nextLong(least >= bound) throws IllegalArgumentException
 */
public void testNextLongBadBounds() {
    long[][] badBoundss = {
        { 17L, 2L },
        { -42L, -42L },
        { Long.MAX_VALUE, Long.MIN_VALUE },
    };
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    for (long[] badBounds : badBoundss) {
        try {
            rnd.nextLong(badBounds[0], badBounds[1]);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ThreadLocalRandomTest.java

示例6: testSortTaskDemo

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
/**
 * SortTask demo works as advertised
 */
public void testSortTaskDemo() {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    long[] array = new long[1007];
    for (int i = 0; i < array.length; i++)
        array[i] = rnd.nextLong();
    long[] arrayClone = array.clone();
    testInvokeOnPool(mainPool(), new SortTask(array));
    Arrays.sort(arrayClone);
    assertTrue(Arrays.equals(array, arrayClone));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:RecursiveActionTest.java

示例7: handle

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
/**
 * Called when the event is sent.
 *
 * @param event The event object.
 */
@Override
public void handle(@NotNull MessageReceivedEvent event) {
    if (!isMyCommand(event)) {
        return;
    }
    logger.traceEntry("Received uptime command");
    try {

        @NotNull List<String> args = Commands.splitByWhitespace(event.getMessage().getContent().trim());

        @NotNull String firstArg = args.get(0).substring(1);
        if (DICE_ROLLS.contains(firstArg)) {
            handleDiceRoll(event, args);
            return;
        }
        if (COIN_ROLLS.contains(firstArg)) {
            handleCoinToss(event, args);
            return;
        }
        long iterations = 1;
        if (args.size() > 2 && LONG_PATTERN.matcher(args.get(1)).find() && LONG_PATTERN.matcher(args.get(2)).find()) {
            long origin = Long.parseUnsignedLong(args.get(1));
            long bound = Long.parseUnsignedLong(args.get(2));
            if (origin > bound) {
                long h = origin;
                origin = bound;
                bound = h;
            }
            if (args.size() > 3 && INT_PATTERN.matcher(args.get(3)).find()) {
                iterations = Math.min(12, Integer.parseUnsignedInt(args.get(3)));
            }
            long sIterations = 0;

            ThreadLocalRandom random = ThreadLocalRandom.current();
            EmbedBuilder builder = MessageUtils.getEmbedBuilder(event.getMessage().getAuthor());
            long sum = 0;
            while (iterations-- != 0) {
                long num = random.nextLong(origin, bound + 1);
                sum += num;
                builder.appendField("[" + origin + "," + bound + "]", num + "", true);
                sIterations++;
            }
            builder.withTitle("Generated " + sIterations + " random " + (sIterations == 1 ? " number" : " numbers"));
            builder.withDescription("Average result: " + sum / sIterations);

            sendThenDelete(MessageUtils.getMessageBuilder(event.getMessage())
                    .withEmbed(builder.build()));
            delete(event.getMessage());
        } else {
            sendThenDelete(MessageUtils.getMessageBuilder(event.getMessage())
                    .withContent("Usage: random origin bound <iterations>"));
        }

    } catch (Exception e) {
        logger.error(e);
    }
}
 
開發者ID:ViniciusArnhold,項目名稱:ProjectAltaria,代碼行數:63,代碼來源:RandomNumberCommand.java

示例8: createRandomAppraisal

import java.util.concurrent.ThreadLocalRandom; //導入方法依賴的package包/類
private static long createRandomAppraisal(long lower, long upper) {
	ThreadLocalRandom random = ThreadLocalRandom.current();
	return random.nextLong(lower, upper);
}
 
開發者ID:InsightEdge,項目名稱:geospatial-catastrophe-modeling,代碼行數:5,代碼來源:Factory.java


注:本文中的java.util.concurrent.ThreadLocalRandom.nextLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。