zoukankan      html  css  js  c++  java
  • Disruptor分布式id生成策略

    需要的pom文件:

     <!-- 顺序UUID -->
             <dependency>
                <groupId>com.fasterxml.uuid</groupId>
                <artifactId>java-uuid-generator</artifactId>
                <version>3.1.4</version>
             </dependency> 	
    

      有时间顺序:

    import com.fasterxml.uuid.EthernetAddress;
    import com.fasterxml.uuid.Generators;
    import com.fasterxml.uuid.impl.TimeBasedGenerator;
    
    public class KeyUtil {
    
    	public static String generatorUUID(){
    		TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
    		return timeBasedGenerator.generate().toString();
    	}
    	
    	public static void main(String[] args) {
    		System.err.println(KeyUtil.generatorUUID());
    		System.err.println(KeyUtil.generatorUUID());
    	}
    }
    

      

     

    以下两种方式都不合适:

     

     

     

    分布式生成ID架构图:

  • 相关阅读:
    oracle 主键自动地址实现
    解构赋值
    那些朋友那些话系列
    那些朋友那些话
    白鹭记事
    该如何存在
    上海秋季HCC小记
    For the person you never see again
    寻城记
    2013年的国庆
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/11110018.html
Copyright © 2011-2022 走看看