使用nick和订单id来进行锁定,
如果锁定失败,那么等待.
Queue<Future<Boolean>> queue = new LinkedList<Future<Boolean>>();
final ConcurrentMap<String, String> buyerLock = new ConcurrentHashMap<String, String>();
for (final Trade tbTrade : tbTradeList) {
queue.offer(topExecutePool.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
try {
for(int j=0;j<10;j++){
String existBuyerNickTid = buyerLock.putIfAbsent(tbTrade.getBuyerNick(),""+tbTrade.getTid());
if(existBuyerNickTid==null){
break;
}
Thread.sleep(5*1000L);
continue;
}
..............................................
} catch (Exception e) {
logger.error(e);
}finally{
buyerLock.remove(tbTrade.getBuyerNick());
}
return Boolean.TRUE;
}
}));
}