当前位置:网站首页>浅浅的谈一下ThreadLocalInsecureRandom
浅浅的谈一下ThreadLocalInsecureRandom
2022-07-05 19:46:00 【步尔斯特】
今天看了一眼随机数相关,无意间发现了这个类。
这看起来真不错啊,有继承了SecurityRandom,又带有ThreadLocal字样,难道拥有了二者的特性,成为了结合体?
我们来一探究竟。
先来看看它是如何生成随机数的
@Override
public int nextInt() {
return random().nextInt();
}
跟踪,看来这个random方法是它核心了。
private static Random random() {
return PlatformDependent.threadLocalRandom();
}
PlatformDependent是netty下的,我们日后再说它。
跟踪
public static Random threadLocalRandom() {
return RANDOM_PROVIDER.current();
}
跟踪
private interface ThreadLocalRandomProvider {
Random current();
}
跟踪,哦~
原来在这,原来底层用的还是ThreadLocalRandom啊,不过时jdk7及以上,用jdk的方式实现了。
static {
if (javaVersion() >= 7) {
RANDOM_PROVIDER = new ThreadLocalRandomProvider() {
@Override
@SuppressJava6Requirement(reason = "Usage guarded by java version check")
public Random current() {
return java.util.concurrent.ThreadLocalRandom.current();
}
};
} else {
RANDOM_PROVIDER = new ThreadLocalRandomProvider() {
@Override
public Random current() {
return ThreadLocalRandom.current();
}
};
}
看了一眼netty和jdk下的ThreadLocalRandom实现方式,还是有很大的不同,感兴趣自己去看看吧。
回头看了一眼ThreadLocalInsecureRandom还不是public修饰的,啥也不是,下课。
边栏推荐
- C#应用程序界面开发基础——窗体控制(5)——分组类控件
- 中国银河证券开户安全吗 证券开户
- Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
- PG basics -- Logical Structure Management (user and permission management)
- 5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
- C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
- Reflection and imagination on the notation like tool
- 集合
- c——顺序结构
- 多分支结构
猜你喜欢
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
Apprentissage du projet MMO I: préchauffage
城链科技数字化创新战略峰会圆满召开
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
随机推荐
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
线程池参数及合理设置
MMO project learning 1: preheating
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
如何安全快速地从 Centos迁移到openEuler
爬虫练习题(二)
【无标题】
redis集群模拟消息队列
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
The difference between ID selector and class selector
太牛了,看这篇足矣了
常用运算符与运算符优先级
C application interface development foundation - form control (5) - grouping control
Fuzor 2020 software installation package download and installation tutorial
How to safely and quickly migrate from CentOS to openeuler
力扣 1200. 最小绝对差
JAD installation, configuration and integration idea
What are the reliable domestic low code development platforms?
Shell编程基础(第8篇:分支语句-case in)