当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- The difference between ID selector and class selector
- redis集群模拟消息队列
- Force buckle 1200 Minimum absolute difference
- What does software testing do? What are the requirements for learning?
- Recommended collection, my Tencent Android interview experience sharing
- Using repositoryprovider to simplify the value passing of parent-child components
- The city chain technology Digital Innovation Strategy Summit was successfully held
- Redis cluster simulated message queue
- 面试官:Redis中集合数据类型的内部实现方式是什么?
- 使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)
猜你喜欢
力扣 1200. 最小绝对差
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
Android面试,android音视频开发
Fuzor 2020 software installation package download and installation tutorial
集合
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
城链科技数字化创新战略峰会圆满召开
随机推荐
司空见惯 - 英雄扫雷鼠
Django uses mysqlclient service to connect and write to the database
shell编程基础(第9篇:循环)
多分支结构
[untitled]
【无标题】
S7-200smart uses V90 Modbus communication control library to control the specific methods and steps of V90 servo
【obs】libobs-winrt :CreateDispatcherQueueController
关于 Notion-Like 工具的反思和畅想
通配符选择器
MMO project learning 1: preheating
函数的概念及语法
Is it safe to open a mobile stock account? Is it reliable?
安卓面试宝典,2022Android面试笔试总结
Is it safe for Guohai Securities to open an account online?
Information / data
MMO项目学习一:预热
What do software test engineers do? How about the prospect of treatment?
C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
MySQL中字段类型为longtext的值导出后显示二进制串方式