当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- aggregate
- 【无标题】
- [hard core dry goods] which company is better in data analysis? Choose pandas or SQL
- [untitled]
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
- Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
- 打新债在哪里操作开户是更安全可靠的呢
- [AI framework basic technology] automatic derivation mechanism (autograd)
- Gstreamer中的task
猜你喜欢
四万字长文说operator new & operator delete
城链科技数字化创新战略峰会圆满召开
What do software test engineers do? How about the prospect of treatment?
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
完爆面试官,一线互联网企业高级Android工程师面试题大全
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
MMO project learning 1: preheating
The city chain technology Digital Innovation Strategy Summit was successfully held
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
What are the reliable domestic low code development platforms?
随机推荐
openh264解码数据流向分析
Concept and syntax of function
安信证券在网上开户安全吗?
How to convert word into PDF? Word to PDF simple way to share!
Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
深度学习 卷积神经网络(CNN)基础
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
Postman core function analysis - parameterization and test report
全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
PHP利用ueditor实现上传图片添加水印
What does software testing do? What are the requirements for learning?
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
【硬核干货】数据分析哪家强?选Pandas还是选SQL
id选择器和类选择器的区别
shell编程基础(第9篇:循环)
Which securities company is better and which platform is safer for mobile account opening
Fuzor 2020软件安装包下载及安装教程
使用 RepositoryProvider简化父子组件的传值