实施DB会话连接大家好 我们正在开发在Struts2,Spring的JPA的应用程序,在这个应用中,我们使用sessions.xml和persistence.xml中管理Oracle数据库会话。使用JPA持续在春季
在Spring的serviceimpl类构造函数中,通过调用getSession()方法,我们正在初始化serverSession变量。
在这里,我附上了我们正在使用该项目的Coeds。
在默认地将Impl构造
serverSession=getSession();
和方法执行程序
try {
createConnection(serverSession);
/* call stored procudure */
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("ORACLE_USP");
call.addNamedArgumentValue("ARG1", value);
call.addNamedOutputArgument("OUTPUTVAL", "P_OUTPUTVAL", Integer.class);
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
actionplanforum_id = (Integer) serverSession.executeQuery(query);
} catch (DatabaseException e) {
LOGGER.error("DatabaseException" + e);
} finally {
releaseJTSCon(serverSession);
}
protected ServerSession getSession() throws Exception {
ServerSession sSession = (ServerSession) SessionManager.getManager().getSession("dbsession");
if (!sSession.isConnected()) {
sSession.connect();
}
return sSession;
}
public void createConnection(ServerSession sSession) {
if (!sSession.isLoggedIn()) {
sSession.login();
}
}
protected void releaseJTSCon(ServerSession sSession) {
try {
sSession.releaseJTSConnection();
}catch (DatabaseException e) {
LOGGER.error("Error in releasing DB connection resources");
}
这是不使用EntityManger一个正确的方法,使用这种方法时,当更多的流量来了,我有oracle中有很多db连接(大部分处于空闲阶段)。
任何人可以实施正确的方法帮助。
我有jsp页面,它使用3个Ajax调用struts2操作那些返回的对象列表显示在jsp页面(表格格式)。在测试结束时,为200名用户(使用jmeter)进行负载测试时,我有大约80 db的连接。这是为什么呢bahaving所以..我已经尝试过直接连接的ServerSession(一个我用分组)和使用的ClientSession(詹姆斯的建议),但两者都没有MAJAR diffrence.Is这是一个公认的行为。为什么不是0连接? – gnanz 2011-05-03 10:48:48