早上好
我正在测试并发数据库。
测试是用JMeter启动50个请求,代码将寄存器保存在数据库中并测量时间
问题在于休眠状态没有关闭任何会话。我的数据库有200个连接。
服务器被阻止,并且有请求永无止境。
我的休眠cfg:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="prueba">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">PROD</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521/orclpdb1</property>
<property name="hibernate.connection.username">PROD</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.default_schema">PROD</property>
<property name="hibernate.show_sql">false</property>
<property name="connection.pool_size">200</property>
<mapping class="es.pers.com.accesobd.model.TestTable"/>
<mapping class="es.pers.com.accesobd.model.TestTableId"/>
</session-factory>
</hibernate-configuration>
HibernateUtil类
package es.pers.com.control;
import java.io.File;
import org.hibernate.SessionFactory;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory(){
try {
// Create the SessionFactory from hibernate.cfg.xml
org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration();
configuration.configure(new File("C:\\workspace\\bdd\\hibernate.cfg.xml"));
System.out.println("Hibernate Configuration loaded");
ServiceRegistryBuilder serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(serviceRegistry.buildServiceRegistry());
} catch (RuntimeException e) {
System.out.println("RuntimeException");
} catch (Exception e) {
System.out.println("Exception");
} catch (Throwable e) {
e.printStackTrace();
}finally {
}
return sessionFactory;
}
public static void closeSessionFactory(){
try {
sessionFactory.close();
} catch (RuntimeException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}finally {
}
}
}
代码保存在数据库中
public void saveDB(){
Session session =null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
TestTable pru = new TestTable();
TestTableId id = new TestTableId();
long info = System.currentTimeMillis();
id.setCampo1(info+"1");
id.setCampo2(info+"2");
id.setCampo3(info+"3");
id.setCampo4(info+"4");
id.setCampo5(info+"5");
pru.setId(id);
long ini = System.currentTimeMillis();
session.save(pru);
session.getTransaction().commit();
System.out.println("# Tiempo: "+(System.currentTimeMillis()-ini));
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}finally {
if(null!=session) {
try {
session.close();
HibernateUtil.closeSessionFactory();
} catch (Exception e2) {
System.out.println("Error close connection");
}
}
}
}
还有JBoss错误:
11:07:39,948 ERROR [stderr] (http--127.0.0.1-8080-19) org.hibernate.exception.GenericJDBCException: Could not open connection
11:07:39,952 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
11:07:39,954 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
11:07:39,955 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
11:07:39,956 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
11:07:39,958 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
11:07:39,959 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
11:07:39,961 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
11:07:39,962 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1309)
11:07:39,963 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.servicios.wsimpl.tra.ws.WS_retSkeleton.ejecutarLogica(WS_retSkeleton.java:143)
11:07:39,965 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.servicios.wsimpl.AbstractSkeleton.ejecutar(AbstractSkeleton.java:82)
11:07:39,974 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.servicios.wsimpl.AbstractSkeleton.ejecutarOperacionWS(AbstractSkeleton.java:383)
11:07:39,976 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.servicios.wsimpl.tra.ws.WS_retSkeleton.Op(WS_retSkeleton.java:53)
11:07:39,978 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.logica.logicaimpl.MessageReceiverInOut.generateEnvelope(MessageReceiverInOut.java:203)
11:07:39,979 ERROR [stderr] (http--127.0.0.1-8080-19) at es.pers.com.logica.logicaimpl.MessageReceiverInOut.invokeBusinessLogic(MessageReceiverInOut.java:56)
11:07:39,981 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
11:07:39,982 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
11:07:39,984 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
11:07:39,985 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
11:07:39,986 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
11:07:39,988 ERROR [stderr] (http--127.0.0.1-8080-19) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
11:07:39,989 ERROR [stderr] (http--127.0.0.1-8080-19) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
11:07:39,991 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
11:07:39,992 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
11:07:39,994 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
11:07:39,995 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
11:07:39,996 ERROR [stderr] (http--127.0.0.1-8080-19) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
11:07:40,005 ERROR [stderr] (http--127.0.0.1-8080-19) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
11:07:40,007 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
11:07:40,009 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
11:07:40,010 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
11:07:40,011 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
11:07:40,012 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
11:07:40,014 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
11:07:40,015 ERROR [stderr] (http--127.0.0.1-8080-19) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
11:07:40,017 ERROR [stderr] (http--127.0.0.1-8080-19) at java.lang.Thread.run(Thread.java:745)
11:07:40,018 ERROR [stderr] (http--127.0.0.1-8080-19) Caused by: java.sql.SQLException: Listener refused the connection with the following error:
11:07:40,019 ERROR [stderr] (http--127.0.0.1-8080-19) ORA-12519, TNS:no appropriate service handler found
11:07:40,020 ERROR [stderr] (http--127.0.0.1-8080-19)
11:07:40,021 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
11:07:40,023 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
11:07:40,026 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
11:07:40,027 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
11:07:40,028 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
11:07:40,029 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
11:07:40,031 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
11:07:40,038 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
11:07:40,040 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
11:07:40,041 ERROR [stderr] (http--127.0.0.1-8080-19) at java.sql.DriverManager.getConnection(DriverManager.java:571)
11:07:40,042 ERROR [stderr] (http--127.0.0.1-8080-19) at java.sql.DriverManager.getConnection(DriverManager.java:187)
11:07:40,043 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173)
11:07:40,045 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:277)
11:07:40,046 ERROR [stderr] (http--127.0.0.1-8080-19) at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
11:07:40,048 ERROR [stderr] (http--127.0.0.1-8080-19) ... 31 more
11:07:40,049 ERROR [stderr] (http--127.0.0.1-8080-19) Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
11:07:40,051 ERROR [stderr] (http--127.0.0.1-8080-19) ORA-12519, TNS:no appropriate service handler found
11:07:40,052 ERROR [stderr] (http--127.0.0.1-8080-19)
11:07:40,053 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.net.ns.NSProtocol.connect(NSProtocol.java:361)
11:07:40,054 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
11:07:40,056 ERROR [stderr] (http--127.0.0.1-8080-19) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
11:07:40,057 ERROR [stderr] (http--127.0.0.1-8080-19) ... 40 more