java jdk自带提供的UUID 多线程并发会生成重复id

价 格: ¥ 1

分 类: java

发 布: 2018-01-01 17:47

审 核: 2018-01-01 17:47

作 者: Admin

下 载: 178次

import java.util.Random;
import java.util.UUID;


public class Test {

public static void main(String[] args) {
for(int i=0;i<5;i++){
new Thread(new Runnable() {
@Override
public void run() {
System.out.println(generateSequenceID());
}
}).start();
}
}

public static String generateSequenceID(){
String uuid = UUID.randomUUID().toString();
String ranEight = String.format("%08d", new Random().nextInt(99999999));
return uuid +"--"+ ranEight;
}
}

java jdk自带提供的UUID 多线程并发会生成重复id