当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- Reinforcement learning - learning notes 4 | actor critical
- Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022
- C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
- 使用 RepositoryProvider简化父子组件的传值
- Webuploader file upload drag upload progress monitoring type control upload result monitoring control
- Relationship between floating elements and parent and brother boxes
- third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- PG basics -- Logical Structure Management (user and permission management)
- Hiengine: comparable to the local cloud native memory database engine
猜你喜欢

What is the core value of testing?

MMO項目學習一:預熱

Worthy of being a boss, byte Daniel spent eight months on another masterpiece

Add data to excel small and medium-sized cases through poi
成功入职百度月薪35K,2022Android开发面试解答

深度學習 卷積神經網絡(CNN)基礎
![[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp](/img/32/738df44b6005fd84b4a9037464e61e.jpg)
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp
![[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*](/img/cc/172684664a9115943d45b0646ef110.png)
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*

How about testing outsourcing companies?

【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
随机推荐
[AI framework basic technology] automatic derivation mechanism (autograd)
MMO project learning 1: preheating
浮动元素与父级、兄弟盒子的关系
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
Do you know several assertion methods commonly used by JMeter?
从零实现深度学习框架——LSTM从理论到实战【实战】
Postman核心功能解析-参数化和测试报告
C#应用程序界面开发基础——窗体控制(5)——分组类控件
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
Xaas trap: all things serve (possible) is not what it really needs
Reptile exercises (II)
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
使用 RepositoryProvider简化父子组件的传值
C application interface development foundation - form control (5) - grouping control
C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
Is it safe to open a mobile stock account? Is it reliable?
如何在2022年更明智地应用智能合约?