配置了Spring的 OpenSessionInViewFilter 导致 系统性能低下,批量操作都会使服务器卡死
各位:如何解决这个问题呢?网上看到解决方式:
session.setFlushMode(FlushMode.AUTO);
session.save(care);
session.flush();
但都解决不了问题?
各位:如何解决这个问题呢?网上看到解决方式:
session.setFlushMode(FlushMode.AUTO);
session.save(care);
session.flush();
但都解决不了问题?
package com.anxin.util;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {
/**
* we do a different flushmode than in the codebase
* here
*/
protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
session.setFlushMode(FlushMode.COMMIT);
return session;
}
/**
* we do an explicit flush here just in case
* we do not have an automated flush
*/
protected void closeSession(Session session, SessionFactory factory) {
session.flush();
super.closeSession(session, factory);
}
}
然后在web.xml中再配置一下就OK了
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>com.anxin.util.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
hibernate推荐的连接池就是c3p0,这个是必须要使用的。
你可以不延时加载啊、。