雪花アルゴリズムはlongタイプidを生成する

982 ワード

依存関係の導入:

	io.shardingsphere
	sharding-core
	3.0.0

ツールクラス:

import io.shardingsphere.core.keygen.DefaultKeyGenerator;

import java.util.Random;
/**
 * 
 *    :
* snowflake * * CreateDate: 2019 10 09 */ public class IdGeneratorSnowflake { private static final int SEED = 255; private static DefaultKeyGenerator defaultKeyGenerator = new DefaultKeyGenerator(); static { DefaultKeyGenerator.setWorkerId(new Random().nextInt(SEED)); } /** * * @return string */ public static long generateId() { return defaultKeyGenerator.generateKey().longValue(); } }

 
idとh 5のインタラクティブ精度の問題:
依存関係の導入: