用单例类 可以做 主键 从单例类中取得。在 单例类中要维护一个主键表,如下
CODENAME , NUM
ID1         100
ID2          200
对主键ID1 生成20 个 将NUM更新成 120   
这样在单例类 中就有了 101 - 120 20个不同的主键。
用到时就从 单例类池中取,没有在从DB中生成就可。

解决方案 »

  1.   

    IBM是使用new Date().getTime作为原ID,然后用sha1或md5加密后作为id,保证不会重复
      

  2.   

    加密方法如下,先将Date类型toString后使用:
    public static String createEncryptionCode(String orginalValue){
    MessageDigest alga=null;
    try{alga = MessageDigest.getInstance(getEncryptionType());
    }catch(NoSuchAlgorithmException e){e.printStackTrace();}
    alga.update(orginalValue.getBytes());
    byte[] digest=alga.digest();
    String hs="";
    String stmp="";
    for (int i=0;i<digest.length;i++){
    stmp=(java.lang.Integer.toHexString(digest[i] & 0XFF));
    if(stmp.length()==1) hs=hs+"0"+stmp;
    else hs=hs+stmp;
    }
    return hs.toUpperCase();
    }
      

  3.   

    须导入:
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;