当前位置: 首页>>代码示例>>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;未经允许,请勿转载。