@Test
public void testSerialNum() throws Exception{
final ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<String,Integer>(5000);
Vector<Thread> threads = new Vector<Thread>();
Thread r = new Thread() {
public void run() {
for (int i = 1; i <= 500; i++) {
String seqNo = serialNum.getLocalNum("444", "t_acc_subject_occur_his", 10);
updateMap(map,seqNo,"r1");
}
}
};
threads.add(r);
Thread r1 = new Thread() {
public void run() {
for (int i = 1; i <= 500; i++) {
String seqNo = serialNum.getLocalNum("444", "t_acc_subject_occur_his", 10);
updateMap(map,seqNo,"r2");
}
}
};
threads.add(r1);
Thread r2 = new Thread() {
public void run() {
for (int i = 1; i <= 500; i++) {
String seqNo = serialNum.getLocalNum("444", "t_acc_subject_occur_his1", 10);
updateMap(map,seqNo,"r3");
}
}
};
threads.add(r2);
r.start();
r1.start();
r2.start();
for (Thread iThread : threads) {
try {
// 等待所有线程执行完毕
iThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for(String str:map.keySet()){
if(map.get(str)>1){
System.out.println(str+"================================================(((((((((((((((((((((((((((="+str+"---"+map.get(str));
}
}
}
public static synchronized void updateMap(ConcurrentHashMap<String, Integer> map,String key,String id){
if(map.containsKey(key)){
Integer i = map.get(key);
map.put("", i+1);
}else{
map.put(key, 1);
}
}
表产生sequence功能,测试并发
最新推荐文章于 2022-02-21 16:05:08 发布