SessionFactoryImpl.get錯誤:java.lang.ArrayIndexOutOfBoundsException: -68問題

來源:互聯網
上載者:User

最近項目在生產環境拋錯:

at org.hibernate.impl.SessionFactoryImpl.get(SessionFactoryImpl.java:339)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:411)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:920)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)

....

上述是調用Hibernate查詢資料query.iterate();後,就拋錯了,根據日誌分析,錯誤記錄檔記錄的一般是java.lang.ArrayIndexOutOfBoundsException: -68,後面是一個-128範圍內的負數,並且根據時間逐漸增大,比如到java.lang.ArrayIndexOutOfBoundsException: -2,然後java.lang.ArrayIndexOutOfBoundsException: -1,然後又輪迴到java.lang.ArrayIndexOutOfBoundsException: -127。

開始看了半天一直在找自己代碼的問題,最後通過查看hibernate源碼SessionFactoryImpl.java的339附近代碼,方法如下:

private synchronized Object get(Object key)
{
Object result = this.softQueryCache.get(key);
if (result != null) {
this.strongRefs[(++this.strongRefIndex % 128)] = result;
}
return result;
}

this.strongRefs[(++this.strongRefIndex % 128)] = result;為第339行,strongRefs數組是初始化長度為128的數組,strongRefIndex被定義為:private transient int strongRefIndex = 0;

strongRefIndex是根據每次擷取資料都遞增1的,根據報錯內容,應該是strongRefIndex為負數了,而且每次也確實在遞增。

通過上述分析,strongRefIndex欄位要不記憶體中被無故修改了,或者就是遞增到int的最大長度2147483647了,導致變為了負數。好像沒有其他辦法,只能重啟網站,重啟後問題果然解決了!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.