本文整理匯總了Java中io.netty.util.internal.PlatformDependent.newConcurrentHashMap方法的典型用法代碼示例。如果您正苦於以下問題:Java PlatformDependent.newConcurrentHashMap方法的具體用法?Java PlatformDependent.newConcurrentHashMap怎麽用?Java PlatformDependent.newConcurrentHashMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.internal.PlatformDependent
的用法示例。
在下文中一共展示了PlatformDependent.newConcurrentHashMap方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: get
import io.netty.util.internal.PlatformDependent; //導入方法依賴的package包/類
@Test
public void get() throws Exception {
List<String> nodeList = new ArrayList<>();
Map<String, List<String>> mm = PlatformDependent.newConcurrentHashMap();
for (int i = 0; i < 100; i++) {
nodeList.add(("Host" + i));
mm.put(("Host" + i), new ArrayList<>());
}
RendezvousHash rendezvousHash =
new RendezvousHash(Funnels.stringFunnel(Charset.defaultCharset()), nodeList);
Random r = new Random();
for (int i = 0; i < 100000; i++) {
String thing = (Integer.toString(r.nextInt(123456789)));
List<String> hosts = rendezvousHash.get(thing.getBytes(), 3);
hosts.forEach(
xs -> {
mm.get(xs).add(thing);
});
}
List<Integer> xx = new ArrayList<>();
mm.keySet()
.forEach(
xs -> {
xx.add(mm.get(xs).size());
});
Double xd = xx.stream().mapToInt(x -> x).average().orElse(-1);
assertEquals(3000, xd.intValue());
}