1

次のコードがあります。「firstnamelastname」のような通常の文字列を渡すとき。ストアドプロシージャはすぐに戻ります。でも、名*で呼ぶと時間がかかります。名*を使用してストアドプロシージャを実行すると、2秒以上かかりません。これが以下のコードです

public List<NameBean> getNameReportJson(final int numberOfResults,
        final String searchValue, final String category, Connection con)
        throws SQLException {

    final List<NameBean> beanList = new ArrayList();
    List<String> resultStrs = new ArrayList<String>();
    final String nameReportStoreProcedure = "{call [sp_SENTRY_INFORMATION_REPORT_NAME_REPORT] (?,?,?,?,?)}";

    Session session = (Session) em.getDelegate();
    StringBuffer sb = new StringBuffer();

    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            CallableStatement cstmt = connection
                    .prepareCall(nameReportStoreProcedure);
            ResultSet rs = null;

            cstmt.setInt("numberOfResults", numberOfResults);
            cstmt.setString("SearchValue", searchValue);
            cstmt.setString("Category", category);
            cstmt.setDate("startDate", null);
            cstmt.setDate("endDate", null);

            rs = cstmt.executeQuery();
            logger.debug("CeReport the ResultSet is: " + rs);
            while (rs.next()) {
                NameBean nameBean = new NameBean();
                String oriName = rs.getString("ORIGINAL NAME");
                String standName = rs.getString("STANDARDIZED NAME");
                String groupName = rs.getString("GROUP NAME");
                long groupId = rs.getLong("GROUP ID");
                nameBean.setOriginalName(oriName);
                nameBean.setStandardName(standName);
                nameBean.setGroupName(groupName);
                nameBean.setGroupID(groupId);
                nameBean.setEntityID(rs.getString("ENTITY ID"));
                beanList.add(nameBean);
            }

        }

    });

    return beanList;
}
4

1 に答える 1

0

原因が見つかりました。この問題は、ストアド プロシージャへの同時要求があったときに発生していました。犯人は発言だった

Session session = (Session) em.getDelegate();

したがって、私がしなければならなかったのは、リクエストごとに EntityManager の新しいインスタンスを作成し、それを使用してセッションを取得することでした。セッションが複数のスレッドによって共有されていたため、テーブルがロックされていたため、問題が発生していました。これが他の人に役立つことを願っています

于 2012-12-07T20:27:22.583 に答える