由于很多时候没有注意到,导致一个service的实现里面的2个方法都加了同一个锁,导致当一个方法繁忙的时候另一个锁的方法死锁,执行不了~~
解决方法,最好就是把执行次数多的方法另外加锁,不要和其他带锁的方法用同一个锁即可:
byte[] lock01 = new byte[0];
public Result synResultByCache(String fid) {
synchronized(lock01){
Result result = null;
if(objectCache.getObjectCache(DFSFile_List_Key+fid)==null){
result = synResultById(fid);
if(result!=null)
objectCache.putObjectInCache(DFSFile_List_Key+fid, result);
}else{
result = (Result)objectCache.getObjectCache(DFSFile_List_Key+fid);
}
return result;
}
}
本文介绍了一个因多个方法使用同一锁而导致的死锁问题,并提供了解决方案:通过为高频率调用的方法单独设置锁来避免死锁现象。
6025

被折叠的 条评论
为什么被折叠?



