zoukankan      html  css  js  c++  java
  • SessionFactoryImpl.get错误:java.lang.ArrayIndexOutOfBoundsException: 68问题

    最近项目在生产环境抛错:

    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了,导致变为了负数。好像没有其他办法,只能重启网站,重启后问题果然解决了!

  • 相关阅读:
    作业3——turtle
    作业2——Python基础
    作业——理解管理信息系统
    测试用例挑选策略
    UVALive 5903 Piece it together(二分图匹配)
    UVALive 4953 Wormly--【提醒自己看题要仔细】
    HDU 3111 Sudoku(精确覆盖)
    FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena
    UVALive 6577 Binary Tree 二叉树的LRU串
    codeforces 425C Sereja and Two Sequences(DP)
  • 原文地址:https://www.cnblogs.com/Lawson/p/2811371.html
Copyright © 2011-2022 走看看