用户ID的代码生成
public class Uid { private static final String machineIdString = Integer.toHexString(new Object().hashCode()); private static final AtomicInteger globalCount = new AtomicInteger(0); private final int count = globalCount.incrementAndGet(); private final long time = System.currentTimeMillis(); /** * Generates a new identifier. */ private Uid() { super(); } /** * Generates a new identifier String. */ public static String generateUidString() { String idString = new Uid().toString(); return idString; } /** * @see Object#toString() */ public String toString() { String timeString = Long.toHexString(time); String countString = Integer.toHexString(count); return machineIdString + "_" + timeString + "_" + countString; } }
学习过程中,难免出错。如果您在阅读过程中遇到不太明白,或者有疑问。欢迎指正...联系邮箱crazyCodeLove@163.com
如果觉得有用,想赞助一下请移步赞助页面:赞助一下