Java的UUID生成工具并发测试
2010-08-20 00:00:00 来源:WEB开发网这里,主要想通过多线程生成UUID测试下,看看是否会重复,效率如何:
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Java的UUID生成工具并发测试
*
* @author leizhimin 2010-7-10 16:25:13
*/
public class TestUUID implements Runnable {
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(5);
for (int i = 0; i < 8; i++) {
pool.execute(new TestUUID());
}
pool.shutdown();
}
public static String genReqID() {
// return UUID.randomUUID().toString().replace("-", "").toUpperCase();
return UUID.randomUUID().toString().toUpperCase();
}
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(genReqID());
}
}
}
更多精彩
赞助商链接