public class OrderGenerater {
private volatile static int serialNo = 0;
private static final String FORMATSTRING = "yyyyMMddHHmmssSSS";
/**
* 使用公平锁防止饥饿
*/
private static final Lock lock = new ReentrantLock(true);
/**
* * 生成订单号,生成规则 时间戳+机器IP最后两位+2位随机数+两位自增序列 <br>
* * 采用可重入锁减小锁持有的粒度,提高系统在高并发情况下的性能 * *
*
* @return
*/
public static String generateOrderNo() {
StringBuilder builder = new StringBuilder();
builder.append(getDateTime(FORMATSTRING)).append(getLastNumOfIP());
builder.append(getRandomNum()).append(getIncrement());
return builder
订单号生成工具
最新推荐文章于 2024-01-15 00:35:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)