当前位置:网站首页>淺淺的談一下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修飾的,啥也不是,下課。
边栏推荐
- The problem of returning the longtext field in MySQL and its solution
- That's awesome. It's enough to read this article
- IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
- Password reset of MariaDB root user and ordinary user
- PHP利用ueditor实现上传图片添加水印
- What is the core value of testing?
- redis集群模拟消息队列
- UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- 【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
猜你喜欢
【无标题】
Necessary skills for interview in large factories, 2022android will not die, I will not fall
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
How MySQL queries and modifies JSON data
What is the core value of testing?
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Hiengine: comparable to the local cloud native memory database engine
众昂矿业:2022年全球萤石行业市场供给现状分析
随机推荐
Reflection and imagination on the notation like tool
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
强化学习-学习笔记4 | Actor-Critic
How MySQL queries and modifies JSON data
Fundamentals of shell programming (Part 8: branch statements -case in)
测试外包公司怎么样?
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
What do software test engineers do? How about the prospect of treatment?
okcc呼叫中心有什么作用
How to realize the Online timer and offline timer in the game
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
PHP利用ueditor实现上传图片添加水印
再忙不能忘安全
集合
Debezium series: record the messages parsed by debezium and the solutions after the MariaDB database deletes multiple temporary tables
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用