表产生sequence功能,测试并发

	@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);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值