报错:Row was updated or deleted by another transaction

controller里面多线程这块代码
List<Integer> list = db.rows(communitySql).asList()
ExecutorService evaluatePool = Executors.newFixedThreadPool(10)
List<Future<List<Object>>> futures = new ArrayList<>(10);
for (int i = 0;i<10;i++){
try {
futures.add(evaluatePool.submit(new ComputeThreadService(list,this.computeDistanceService)))
}
catch(Exception e) {
e.printStackTrace()
}
}
try {
//处理
List<Object> result = new ArrayList<>();
int i = 0
for(Future<List<Object>> future : futures){
//合并操作
result.addAll(future.get())
}
println "result.size()=========="+result.size()
//批量插入
result.each{
it.save()
i++
if(i % 1000 == 0){
sessionFactory.currentSession.flush()
sessionFactory.currentSession.clear()
}
}
} catch (Exception e) {
e.printStackTrace()
}
ComputeThreadService中只调用这个:
@Override
List<Object> call() throws Exception {
def obj = null
List<Object> retList = new ArrayList<Object>();
for(int i=0;i<list.size();i++){
obj = list.get(i)?.community_id
//处理逻辑
def distance = computeDistanceService.communityDistance(obj.toString())
retList.addAll(distance)
}
//返回处理结果
return retList;
}
service中只有这一处会连接数据库插入:Community community = null
if(Community.findByCommunityId(communityId) == null){
community = new Community()
}else{
community = Community.findByCommunityId(communityId)
}
community.communityId = communityResult[0]?.community_id
community.name = communityResult[0]?.communityname
if(City.findByCityId(communityResult[0]?.city_id))
{
community.city = City.findByCityId(communityResult[0]?.city_id)
}
else
{
def city = new City()
city.cityId = communityResult[0]?.city_id
city.cityCode = communityResult[0]?.city_code
city.save()
community.city = city
}
if(community.validate())
{
community.save(flush:true)
}
else
{
println community.errors
}
找了很久,没有找到有效的解决方案,求大神提供一个解决办法