问题的背景
公司老的系统原先采用的时间戳生成订单号,导致了如下情形
打断一下:大家知道怎么查系统某项重复的数据吧
SELECT * FROM XX表 WHERE 重复项 in( SELECT 重复项 FROM XX表 GROUP BY 重复项 HAVING count(1) >= 2)
解决方法
不得了,这样重复岂不是一单成功三方回调导致另一单也成功了。
多个服务怎么保证生成的订单号唯一呢?
先上code
package com.zhongjian.util;
public class IdWorkerUtil{
private long workerId;
private long datacenterId;
private long sequence;
public IdWorkerUtil(long workerId, long datacenterId, long sequence){
// sanity check for workerId
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0",maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0",maxDatacenterId)<