当前位置:网站首页>淺淺的談一下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修飾的,啥也不是,下課。
边栏推荐
- 深度學習 卷積神經網絡(CNN)基礎
- Django uses mysqlclient service to connect and write to the database
- 司空见惯 - 英雄扫雷鼠
- 城链科技数字化创新战略峰会圆满召开
- 四万字长文说operator new & operator delete
- [FAQ] summary of common causes and solutions of Huawei account service error 907135701
- 使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
- Analysis of openh264 decoded data flow
- [OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
- 测试的核心价值到底是什么?
猜你喜欢
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
Common - Hero Minesweeper
四万字长文说operator new & operator delete
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
Interviewer: what is the internal implementation of set data types in redis?
Hiengine: comparable to the local cloud native memory database engine
PHP利用ueditor实现上传图片添加水印
通过POI追加数据到excel中小案例
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
随机推荐
How MySQL queries and modifies JSON data
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Win10 x64环境下基于VS2017和cmake-gui配置使用zxing以及opencv,并实现data metrix码的简单检测
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
通配符选择器
S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
The problem of returning the longtext field in MySQL and its solution
okcc呼叫中心有什么作用
力扣 729. 我的日程安排表 I
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
挖财钱堂教育靠谱安全吗?
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
No matter how busy you are, you can't forget safety
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
ACM getting started Day1
Wildcard selector
软件测试工程师是做什么的?待遇前景怎么样?
Concept and syntax of function
Gstreamer中的task
Base du réseau neuronal de convolution d'apprentissage profond (CNN)