Java Code Examples for io.netty.util.internal.ThreadLocalRandom#current()

The following examples show how to use io.netty.util.internal.ThreadLocalRandom#current() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelManager.java    From simple-message-push with MIT License 6 votes vote down vote up
@Override
public void channelActive(ChannelHandlerContext ctx) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    int delay = random.nextInt(5, 10);

    // 每一条新连接,都是5~10秒之后发消息
    ctx.executor().scheduleAtFixedRate(() -> {
        PushMessage pushMessage = new PushMessage();
        pushMessage.setMessageId(UUID.randomUUID().toString());
        pushMessage.setContent("hello,world!");
        pushMessage.setTimestamp(System.currentTimeMillis());
        messageStorage.setObject(pushMessage.getMessageId(), pushMessage);
        ctx.channel().writeAndFlush(pushMessage);
    }, delay, delay, TimeUnit.SECONDS);

}
 
Example 2
Source File: UnitHelp.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static int[] randomIntArray(final int length, final int range) {
    final int[] array = new int[length];
    final Random generator = ThreadLocalRandom.current();
    for (int i = 0; i < array.length; i++) {
        array[i] = generator.nextInt(range);
    }
    return array;
}
 
Example 3
Source File: ThreadLocalInsecureRandom.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
private static Random random() {
    return ThreadLocalRandom.current();
}