当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- 大厂面试必备技能,2022Android不死我不倒
- 【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
- How to realize the Online timer and offline timer in the game
- Xaas trap: all things serve (possible) is not what it really needs
- Gstreamer中的task
- Android面试,android音视频开发
- Using repositoryprovider to simplify the value passing of parent-child components
- JMeter 常用的几种断言方法,你会了吗?
- C application interface development foundation - form control (5) - grouping control
- S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
猜你喜欢

That's awesome. It's enough to read this article

MMO項目學習一:預熱

Using repositoryprovider to simplify the value passing of parent-child components

2022 the latest big company Android interview real problem analysis, Android development will be able to technology

40000 word Wenshuo operator new & operator delete

力扣 729. 我的日程安排表 I

C#应用程序界面开发基础——窗体控制(5)——分组类控件

third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl

如何安全快速地从 Centos迁移到openEuler

Force buckle 1200 Minimum absolute difference
随机推荐
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
Hiengine: comparable to the local cloud native memory database engine
How to convert word into PDF? Word to PDF simple way to share!
redis集群模拟消息队列
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
深度學習 卷積神經網絡(CNN)基礎
Fuzor 2020軟件安裝包下載及安裝教程
Is it safe for China Galaxy Securities to open an account? Securities account opening
函数的概念及语法
Android interview, Android audio and video development
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
什么是面上项目
安卓面试宝典,2022Android面试笔试总结
强化学习-学习笔记4 | Actor-Critic
Complete interview questions for interviewers and senior Android engineers in front-line Internet enterprises
Add data to excel small and medium-sized cases through poi
【无标题】
Apprentissage du projet MMO I: préchauffage
测试外包公司怎么样?
Postman core function analysis - parameterization and test report