Use ThreadLocalRandom where possible

This commit is contained in:
Trustin Lee 2013-07-07 12:37:36 +09:00
parent 1fa087ecbf
commit 2b2f8db5d2
3 changed files with 6 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.stream.ChunkedMessageInput;
import io.netty.util.internal.ThreadLocalRandom;
import java.io.File;
import java.io.IOException;
@ -40,7 +41,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Random;
import java.util.regex.Pattern;
import static io.netty.buffer.Unpooled.*;
@ -265,8 +265,7 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpContent>
*/
private static String getNewMultipartDelimiter() {
// construct a generated delimiter
Random random = new Random();
return Long.toHexString(random.nextLong()).toLowerCase();
return Long.toHexString(ThreadLocalRandom.current().nextLong()).toLowerCase();
}
/**

View File

@ -18,6 +18,7 @@ package io.netty.test.udt.util;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.StatusUDT;
import io.netty.util.internal.ThreadLocalRandom;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -222,7 +223,7 @@ public final class UnitHelp {
public static int[] randomIntArray(final int length, final int range) {
final int[] array = new int[length];
final Random generator = new Random(0);
final Random generator = ThreadLocalRandom.current();
for (int i = 0; i < array.length; i++) {
array[i] = generator.nextInt(range);
}

View File

@ -21,6 +21,7 @@ import io.netty.buffer.ByteBufHolder;
import io.netty.util.DefaultAttributeMap;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.ThreadLocalRandom;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
@ -30,7 +31,6 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.util.Random;
import java.util.concurrent.ConcurrentMap;
/**
@ -42,15 +42,13 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
static final ConcurrentMap<Integer, Channel> allChannels = PlatformDependent.newConcurrentHashMap();
private static final Random random = new Random();
/**
* Generates a negative unique integer ID. This method generates only
* negative integers to avoid conflicts with user-specified IDs where only
* non-negative integers are allowed.
*/
private static Integer allocateId(Channel channel) {
int idVal = random.nextInt();
int idVal = ThreadLocalRandom.current().nextInt();
if (idVal > 0) {
idVal = -idVal;
} else if (idVal == 0) {