当前位置:网站首页>浅浅的谈一下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修饰的,啥也不是,下课。
边栏推荐
- 手机股票开户安全吗?靠不靠谱啊?
- Mysql如何对json数据进行查询及修改
- MySql中的longtext字段的返回问题及解决
- Django使用mysqlclient服务连接并写入数据库的操作过程
- 微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
- 软件测试是干什么的?学习有啥要求?
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- acm入门day1
- 中国银河证券开户安全吗 证券开户
猜你喜欢

微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
The problem of returning the longtext field in MySQL and its solution

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

aggregate
![[hard core dry goods] which company is better in data analysis? Choose pandas or SQL](/img/70/a79c4a1724c11e208814de2d9cf553.png)
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL

Xaas trap: all things serve (possible) is not what it really needs
MySql中的longtext字段的返回问题及解决

通过POI追加数据到excel中小案例

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

IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
随机推荐
Django使用mysqlclient服务连接并写入数据库的操作过程
Android interview, Android audio and video development
ACM getting started Day1
C#应用程序界面开发基础——窗体控制(5)——分组类控件
Float. The specific meaning of the return value of floattorawintbits is to convert float into byte array
Analysis of openh264 decoded data flow
How to safely and quickly migrate from CentOS to openeuler
Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo
Hiengine: comparable to the local cloud native memory database engine
PG basics -- Logical Structure Management (user and permission management)
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
[AI framework basic technology] automatic derivation mechanism (autograd)
Tasks in GStreamer
redis集群模拟消息队列
测试的核心价值到底是什么?
众昂矿业:2022年全球萤石行业市场供给现状分析
【合集- 行业解决方案】如何搭建高性能的数据加速与数据编排平台
关于 Notion-Like 工具的反思和畅想
通配符选择器
大厂面试必备技能,2022Android不死我不倒