最近做項目出現一個java.lang.StackOverflowError異常。弄了半天,又是問高手,又是查資料的。最後發現,解決問題啦!特記錄下來!
StackOverflowError是由於當前線程的棧滿了 ,也就是函數調用層級過多導致。
比如死遞歸。
如:
public String homePage(){
this.findAllNews();
return "shouye";
}
public String findAllNews(){
List newslist= hotnewsService.findAll();
HotnewsDto hotnews= (HotnewsDto) newslist.get(0);//得到第一條新聞
String content=hotnews.getContent();
String subcontent=content.substring(0, 80);//截取這條新聞信息內容在首頁部分顯示
super.setRequestAttribute("hotnews", hotnews);
super.setRequestAttribute("newslist", newslist);
super.setRequestAttribute("subcontent", subcontent);
return homePage();
}
如紅色標記處,這樣子調用的方法,相當於一個無限循環了!