一个线程的run方法里使用递归方法,出了Bug。
private boolean ispass(String creationId){
List maps =creationService.getCreationById(creationId);
if(maps != null && maps.size()>0){
Map m = maps.get(0);
String state= (String) m.get("STATE");
if(state != null && state.equals("0")){
return true;
}else{
try {
if(falg == 10){
return false;
}
Thread.sleep(1000 * 60);
falg++;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
ispass(creationId);
}
}else{
return false;
}
return false;
}
同事的解决办法,修改代码通过抛出异常的方式,也算解决了。当然了我不认可 。:)
private boolean ispass(String creationId) throws SecussException{
List maps =creationService.getCreationById(creationId);
if(maps != null && maps.size()>0){
Map m = maps.get(0);
String state= (String) m.get("STATE");
if(state != null && state.equals("0")){
throw new SecussException("ok");
}else{
try {
if(falg == 10){
return false;
}
Thread.sleep(1000 * 60);
falg++;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
ispass(creationId);
}
}else{
return false;
}
return false;
}
我的解决办法:调试代码,发现问题根源,该返回的地方,没返回;不该返回的地方,返回了错误的值。
private boolean ispass(String creationId){
List maps =creationService.getCreationById(creationId);
if(maps != null && maps.size()>0){
Map m = maps.get(0);
String state= (String) m.get("STATE");
if(state != null && state.equals("0")){
return true;
}else{
try {
if(falg == 10){
return false;
}
Thread.sleep(1000 * 60);
falg++;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return ispass(creationId);
}
}else{
return false;
}
}