附:工具类ZlkUtil.java
package com.zlk.util;
import java.util.Calendar;
import java.util.Random;
public class ZlkUtil {
/**
* 获得唯一字符串的方法(str+"_"+毫秒数+4位随机数)(循环添加的时候不建议用,可能出现重复)
*
* @param str
* @return
*/
public static String getCoustomKeyID(String str) {
Random rand = new Random();
return str + "_" + Calendar.getInstance().getTimeInMillis()+ (rand.nextInt(9999 - 1000 + 1) + 1000);
}
/**
* 单例模式生成唯一字符串
*
* @return
*/
public static synchronized String getUniqueString() {
if (generateCount > 99999) generateCount = 0;
String uniqueNumber = Long.toString(System.currentTimeMillis())+ Integer.toString(generateCount);
generateCount++;
return uniqueNumber;
}
private static final int MAX_GENERATE_COUNT = 99999;
private static int generateCount = 0;
}