我在上一篇文章java中试图解决我的问题。sql。SQLRecoverableException:已关闭连接。我尝试了c3p0连接。财产如下:,
<property name="hibernate.connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="dialect"> org.hibernate.dialect.Oracle10gDialect </property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.idle_test_period">6000</property>
<property name="hibernate.c3p0.numHelperThreads">9</property>
在JBOSS中部署之后,我开始测试我的web。一开始,它工作得很好,甚至更快。10分钟后,继续加载并超时。当通过服务器时。日志我得到了如下一些警告消息。
00:34:13,162 INFO [com.mchange.v2.c3p0.impl.NewPooledConnection] com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) [c3p0] Exceptions occurred while trying to close a PooledConnection's resources normally.
00:34:13,162 INFO [com.mchange.v2.c3p0.impl.NewPooledConnection] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) [c3p0] NewPooledConnection close Exception.: java.sql.SQLRecoverableException: IO Error: Software caused connection abort: recv failed
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:556) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3984) [ojdbc6.jar:11.2.0.3.0]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:474) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) [c3p0-0.9.1.jar:0.9.1]
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method) [rt.jar:1.6.0_13]
at java.net.SocketInputStream.read(SocketInputStream.java:129) [rt.jar:1.6.0_13]
at oracle.net.ns.Packet.receive(Packet.java:300) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.DataPacket.receive(DataPacket.java:106) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:260) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:185) [ojdbc6.jar:11.2.0.3.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:102) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:61) [ojdbc6.jar:11.2.0.3.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:543) [ojdbc6.jar:11.2.0.3.0]
... 6 more
00:34:13,177 WARN [com.mchange.v2.resourcepool.BasicResourcePool] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@b041ecc: java.sql.SQLException: Some resources failed to close properly while closing com.mchange.v2.c3p0.impl.NewPooledConnection@b041ecc
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:496) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964) [c3p0-0.9.1.jar:0.9.1]
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) [c3p0-0.9.1.jar:0.9.1]
请给出一些解决这个问题的想法。
此问题会在会话关闭且用于会话的连接仍处于活动状态时出现,并且当再次打开新会话时,会打开新会话。这会导致连接池中指定的连接的使用率超过规定的使用率,助手线程也会发挥作用,我的问题就在这里。我更改了Hibernate SessionFactory类,自定义连接提供程序解决了我的问题。变化如下。。。。
public class HibernateSessionFactory {
private staticString CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
public static Session session;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
public HibernateSessionFactory() {
}
public static Session getSession() throws HibernateException {
try {
if (session == null) {
session = sessionFactory.openSession(MyConnectionProvider
.getConn());
} else {
if (session.isOpen() && !session.connection().isClosed()) {
System.out.println("SESSION AVAILABLE...");
MyConnectionProvider.showConnectionDetails();
return session;
}
if (!session.isOpen()) {
System.out.println("SESSION WAS CLOSED AND OPEN AGAIN..");
session = sessionFactory.openSession(MyConnectionProvider
.getConn());
} else if (session.connection().isClosed()) {
System.out.println("CONNECTION WAS CLOSED AND OPENING AGAIN...");
session.close();
session = sessionFactory.openSession(MyConnectionProvider
.getConn());
}
}
MyConnectionProvider.showConnectionDetails();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return session;
}
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
public static Configuration getConfiguration() {
return configuration;
}
}
ang MyConnectionProvider类是
public class MyConnectionProvider {
static String jdbcDriverClass;
static String jdbcUrl;
static String username;
static String password;
static String poolSize = "20";
static ComboPooledDataSource ds;
static {
config(HibernateSessionFactory.getConfiguration().getProperties());
ds = new ComboPooledDataSource();
// System.out.println(" "+jdbcUrl);
ds.setJdbcUrl(jdbcUrl);
// System.out.println(username);
ds.setUser(username);
// System.out.println(password);
ds.setPassword(password);
ds.setMinPoolSize(1);
ds.setMaxPoolSize(20);
}
public static void config(Properties props) {
System.out.println("SETTING CONFIGURATION...");
jdbcDriverClass = props.getProperty(Environment.DRIVER);
jdbcUrl = props.getProperty(Environment.URL);
username = props.getProperty(Environment.USER);
password = props.getProperty(Environment.PASS);
System.out.println(jdbcDriverClass + " " + jdbcUrl + " " + username
+ " " + password + " " + poolSize);
}
public static Connection getConn() {
Connection conn = null;
try {
System.out.println("URL " + ds.getJdbcUrl());
System.out.println("Busy Connections : "
+ ds.getNumBusyConnections("user", "user"));
return ds.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return conn;
}
}
public static void showConnectionDetails() {
try {
System.out.println("Busy Connections : "
+ ds.getNumBusyConnections() + " Connections : "
+ ds.getNumConnections() + " Thread Pool Size : "
+ ds.getThreadPoolSize() + " Active Threads : "
+ ds.getThreadPoolNumActiveThreads() + " Idle Threads : "
+ ds.getThreadPoolNumIdleThreads() + " Pending Tasks : "
+ ds.getThreadPoolNumTasksPending());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我使用weblogic应用服务器和oracle数据库。我使用jdbc与oracle数据库通信。我从weblogic数据源获得连接,并向表中插入一条记录。问题是,当我想关闭连接(插入数据库后)时,我会遇到一个异常(连接已经关闭)。这是我的代码: 但是联系。close语句引发异常: 我试图避免连接。close语句(因为我教过连接是自动关闭的!!但过了一段时间,所有的连接都打开了,因此引发了一个异常)
我正在尝试使用Http将数据发布到REST服务,我已将我的客户端配置如下: 现在我有一个executor service负责调用实际发布,我将上述参数移交给executor service,如下所示: line是我试图发送的JSON负载。 现在,我在executor服务中的方法如下所示: 我在
我已经将我的代码版本从http更改为https,我正在使用HttpClient=HttpClientFactory。getHttpsClient(),用于执行目的。当我第一次尝试运行代码时,它运行良好,下次抛出异常 Java语言lang.IllegalStateException:连接池关闭异常 我使用的是4.5HC。
问题内容: 我想使用OkHttpClient加载URL,如果给定URL的网站以pdf内容类型响应,我将继续下载PDF,否则我想忽略响应。 我的问题是,我是否需要做一些特殊的事情来关闭请求/响应,或者如果我选择不读取响应字节流,是否需要做任何事情来表明我将不使用响应?如果没有,OkHttpClient何时关闭连接? 问题答案: 调用将释放响应所拥有的所有资源。连接池将使连接保持打开状态,但是如果未使
关闭连接标志着服务器和客户端之间的通信结束。使用事件可以关闭连接,标记通信结束后,服务器和客户端之间无法进一步传输消息。由于连接不良,也可能发生事件。 方法代表再见握手。它终止连接,除非连接再次打开,否则不能交换任何数据。 与前面的示例类似,当用户单击第二个按钮时,调用方法。 也可以传递前面提到的代码和原因说明参数,如下所示。 以下代码完整概述了如何关闭或断开Web Socket连接 - 在浏览器
给出错误的方法如下: 如何创建一个没有泄漏的连接?为什么Hikari认为我的conn.close()方法没有关闭连接?任何想法都很欣赏。