简体   繁体   中英

hibernate hangs on accessing prepared statement

our application (about 50 parallel threads) is using hibernate 5.1.0 and works very fine. But from time to time it occurs that 5 or 6 threads stop their work to the same time. No exception, it just stucked and hangs. StackTrace of jConsole points to a hibernate class called ResultSetReturnImpl.java on statement.isWrapperFor( type );

Stack trace: 
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.isTypeOf(ResultSetReturnImpl.java:95)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:58)
org.hibernate.loader.Loader.getResultSet(Loader.java:2115)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1898)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
org.hibernate.loader.Loader.doQuery(Loader.java:919)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
org.hibernate.loader.Loader.doList(Loader.java:2610)
org.hibernate.loader.Loader.doList(Loader.java:2593)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
org.hibernate.loader.Loader.list(Loader.java:2417)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)

content of ResultSetReturnImpl.java:

    public ResultSet extract(PreparedStatement statement) {
    // IMPL NOTE : SQL logged by caller
    Line 58: if ( isTypeOf( statement, CallableStatement.class ) ) {
        // We actually need to extract from Callable statement.  Although
        // this seems needless, Oracle can return an
        // OracleCallableStatementWrapper that finds its way to this method,
        // rather than extract(CallableStatement).  See HHH-8022.
        final CallableStatement callableStatement = (CallableStatement) statement;
        return extract( callableStatement );
    }
    try {
        final ResultSet rs;
        try {
            jdbcExecuteStatementStart();
            rs = statement.executeQuery();
        }
        finally {
            jdbcExecuteStatementEnd();
        }
        postExtract( rs, statement );
        return rs;
    }
    catch (SQLException e) {
        throw sqlExceptionHelper.convert( e, "could not extract ResultSet" );
    }
}

private boolean isTypeOf(final Statement statement, final Class<? extends Statement> type) {
    if ( isJdbc4 ) {
        try {
            // This is "more correct" than #isInstance, but not always supported.
Line 95:            return statement.isWrapperFor( type );
        }
        catch (SQLException e) {
            // No operation
        }
        catch (Throwable e) {
            // No operation. Note that this catches more than just SQLException to
            // cover edge cases where a driver might throw an UnsupportedOperationException, AbstractMethodError,
            // etc.  If so, skip permanently.
            isJdbc4 = false;
        }
    }
    return type.isInstance( statement );
}

System is using ojdbc7.jar. I need to solve it, because hanging threads can't handle following requests and all received messages are lost. I have no idea if it's a hibernate, jdbc, java or database problem and hope that somebody can give me a hint.

Check the database do you have any table locks are there, if any please remove those. After check that what is the concurrent user limit

one more, is your tables are properly indexed, try to check execution time of the query/procedure, if it's more fine tune the query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM