-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
多线程测试有重复序列号 #6
Comments
Hi @huxiaofei, you need to initialise each You can generate up to Valid values for datacenterId & machineId are 5bit each -> 0...31 Try following instead:
|
thank s for @hartmut-co-uk reply. 在实际部署时,纵然有很多的数据中心,上百台服务器,具体到某一个服务器上, |
Hi @huxiaofei If you can't guarantee singletons by tuple <datacenterId, machineId> you logically will have duplicates. If you actually have big data / high volumes of IDs to generate (hundreds of servers?) - you'd need to provide IDs as-a-service and request IDs via API. So you can run a cluster of your 'ID Service' (with different configuration |
上面说得很明白,一个节点就一个单例的SnokeFlake |
Hi, still not a real Unit Test - but I've put together a more proper example of above's example (concurrency/synchronization) which I think might be worth sharing...
Output:
|
public class SnowFlakeKeyTest2 {
private static Set keys = new HashSet();
public static void main(String[] args) throws Exception {
for(int i=0;i<100;i++) {
SnowFlakeKeyTest2.GetKey runner = new SnowFlakeKeyTest2().new GetKey();
new Thread (runner).start();;
}
System.out.println(keys);
}
运行结果,有很多重复
重复:329755153370267648
重复:329755153370267648
重复:329755153370267648
重复:329755153370267648
重复:329755153374461952
重复:329755153374461952
重复:329755153374461952
重复:329755153374461952
重复:329755153378656256
重复:329755153378656256
重复:329755153378656256
重复:329755153378656256
重复:329755153382850560
重复:329755153391239168
重复:329755153391239168
重复:329755153391239168
重复:329755153391239168
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153399627776
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153395433472
重复:329755153403822080
重复:329755153412210688
重复:329755153412210688
重复:329755153412210688
重复:329755153420599296
重复:329755153420599296
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153424793600
重复:329755153433182208
[329755153424793600, 329755153433182208, 329755153403822080, 329755153370267648, 329755153374461952, 329755153378656256, 329755153382850560, 329755153391239168, 329755153395433472, 329755153399627776, 329755153408016384, 329755153412210688, 329755153420599296, 329755153428987904]
重复:329755153433182208
重复:329755153433182208
重复:329755153433182208
重复:329755153433182208
重复:329755153433182208
重复:329755153433182208
重复:329755153437376512
重复:329755153437376512
重复:329755153437376512
重复:329755153437376512
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153441570816
重复:329755153445765120
重复:329755153445765120
The text was updated successfully, but these errors were encountered: