当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
- S7-200SMART利用V90 MODBUS通信控制库控制V90伺服的具体方法和步骤
- Summer Challenge database Xueba notes, quick review of exams / interviews~
- 【无标题】
- 什么是面上项目
- 四万字长文说operator new & operator delete
- Recommended collection, my Tencent Android interview experience sharing
- 从零实现深度学习框架——LSTM从理论到实战【实战】
- 深度學習 卷積神經網絡(CNN)基礎
- third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
猜你喜欢

Summer Challenge database Xueba notes, quick review of exams / interviews~

The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)

软件测试是干什么的?学习有啥要求?

How to apply smart contracts more wisely in 2022?

全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云

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

IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times

微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知

强化学习-学习笔记4 | Actor-Critic

JAD installation, configuration and integration idea
随机推荐
openh264解码数据流向分析
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Fuzor 2020 software installation package download and installation tutorial
Fuzor 2020軟件安裝包下載及安裝教程
The problem of returning the longtext field in MySQL and its solution
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
Concept and syntax of function
Wildcard selector
aggregate
再忙不能忘安全
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
中国银河证券开户安全吗 证券开户
Tasks in GStreamer
Is it safe to open a mobile stock account? Is it reliable?
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
浮动元素与父级、兄弟盒子的关系
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
Gstreamer中的task