当前位置:网站首页>淺淺的談一下ThreadLocalInsecureRandom
淺淺的談一下ThreadLocalInsecureRandom
2022-07-05 19:50: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修飾的,啥也不是,下課。
边栏推荐
- How MySQL queries and modifies JSON data
- 建立自己的网站(16)
- 挖财钱堂教育靠谱安全吗?
- acm入门day1
- 如何在2022年更明智地应用智能合约?
- UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
- Fundamentals of shell programming (Part 8: branch statements -case in)
- Is it safe for Guohai Securities to open an account online?
- 通配符选择器
- S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
猜你喜欢

【硬核干货】数据分析哪家强?选Pandas还是选SQL

集合

如何在2022年更明智地应用智能合约?

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
Android interview classic, 2022 Android interview written examination summary

UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术

Do you know several assertion methods commonly used by JMeter?

How to convert word into PDF? Word to PDF simple way to share!

如何安全快速地从 Centos迁移到openEuler
![[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform](/img/64/08faef0fccec93337f0716ac57dd8e.jpg)
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
随机推荐
Debezium series: parsing the default value character set
How to realize the Online timer and offline timer in the game
MMO項目學習一:預熱
测试的核心价值到底是什么?
How about testing outsourcing companies?
浮动元素与父级、兄弟盒子的关系
shell编程基础(第9篇:循环)
okcc呼叫中心有什么作用
What do software test engineers do? How about the prospect of treatment?
Tasks in GStreamer
Multi branch structure
-v parameter of GST launch
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
JMeter 常用的几种断言方法,你会了吗?
爬虫练习题(二)
40000 word Wenshuo operator new & operator delete
Analysis of openh264 decoded data flow
浅浅的谈一下ThreadLocalInsecureRandom
The problem of returning the longtext field in MySQL and its solution
力扣 729. 我的日程安排表 I