A C D E I L N O S T
A
- AbstractSequence - Class in org.hiylo.components.sequence
-
- AbstractSequence() - Constructor for class org.hiylo.components.sequence.AbstractSequence
-
C
- checkLastTimestamp(long) - Method in class org.hiylo.components.sequence.AbstractSequence
-
D
- DistributedSequence - Class in org.hiylo.components.sequence
-
基于Twitter的Snowflake算法实现分布式高效有序ID生产黑科技(sequence)
SnowFlake的结构如下(每部分用-分开):
0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000
1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0
41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69
10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId
12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号
加起来刚好64位,为一个Long型。
SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
- DistributedSequence() - Constructor for class org.hiylo.components.sequence.DistributedSequence
-
E
- EnableDistributedSequence - Annotation Type in org.hiylo.components.sequence.annotation
-
- EnableSequence - Annotation Type in org.hiylo.components.sequence.annotation
-
I
- init() - Method in class org.hiylo.components.sequence.DistributedSequence
-
L
- lastTimestamp - Variable in class org.hiylo.components.sequence.AbstractSequence
-
上次生成ID的时间截
N
- nextId() - Method in class org.hiylo.components.sequence.AbstractSequence
-
获取一个long类型的id
- nextId() - Method in class org.hiylo.components.sequence.DistributedSequence
-
获得下一个ID (该方法是线程安全的)
- nextId() - Method in class org.hiylo.components.sequence.SingletonSequence
-
获得下一个ID (该方法是线程安全的)
- nextIdString() - Method in class org.hiylo.components.sequence.AbstractSequence
-
获取一个String类型的id
- nextIdString() - Method in class org.hiylo.components.sequence.DistributedSequence
-
获得下一个ID (该方法是线程安全的)
- nextIdString() - Method in class org.hiylo.components.sequence.SingletonSequence
-
获得下一个ID (该方法是线程安全的)
- now() - Static method in class org.hiylo.components.sequence.SystemClock
-
- nowDate() - Static method in class org.hiylo.components.sequence.SystemClock
-
O
- org.hiylo.components.sequence - package org.hiylo.components.sequence
-
- org.hiylo.components.sequence.annotation - package org.hiylo.components.sequence.annotation
-
S
- SingletonSequence - Class in org.hiylo.components.sequence
-
单机版Snowflake算法
- SingletonSequence() - Constructor for class org.hiylo.components.sequence.SingletonSequence
-
- SingletonSequence(int, int) - Constructor for class org.hiylo.components.sequence.SingletonSequence
-
- SystemClock - Class in org.hiylo.components.sequence
-
高并发场景下System.currentTimeMillis()的性能问题的优化
T
- tilNextMillis(long) - Method in class org.hiylo.components.sequence.AbstractSequence
-
阻塞到下一个毫秒,直到获得新的时间戳
- timeGen() - Method in class org.hiylo.components.sequence.AbstractSequence
-
返回以毫秒为单位的当前时间
A C D E I L N O S T
Copyright © 2021 Clouds Studio. All rights reserved.