玩!框架1.2.4 --- C3P0设置避免通信链路故障做空闲时间 [英] Play! Framework 1.2.4 --- C3P0 settings to avoid Communications link failure do to idle time

查看:194
本文介绍了玩!框架1.2.4 --- C3P0设置避免通信链路故障做空闲时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图自定义我的C3P0设置,以避免在这篇文章底部显示的错误。



有人建议在这个网址--- http://make-it-open.blogspot .com / 2008/12 / sql-error-0 -sqlstate-08s01.html ---调整设置如下:

在hibernate中。 cfg.xml,写入

 < property name =c3p0.min_size> 5< / property> 
< property name =c3p0.max_size> 20< / property>
< property name =c3p0.timeout> 1800< / property>
< property name =c3p0.max_statements> 50< / property>

然后在根类路径文件夹中创建c3p0.properties并写入

  c3p0.testConnectionOnCheckout = true 
c3p0.acquireRetryDelay = 1000
c3p0.acquireRetryAttempts = 1

我试着按照Play的方向进行调整!框架文档,他们说使用db.pool ...,如下所示:

  db.pool.timeout = 1800 
db.pool.maxSize = 15
db.pool.minSize = 5
db.pool.initialSize = 5
db.pool.acquireRetryAttempts = 1
db.pool .preferredTestQuery = SELECT 1
db.pool.testConnectionOnCheckout = true
db.pool.acquireRetryDelay = 1000
db.pool.maxStatements = 50

这些设置不起作用吗?我应该试图以不同的方式设置它们吗?有了这些设置,我仍然得到下面显示的错误,这是由于长时间的空闲时间造成的。



完整的堆栈错误跟踪:

  23:00:44,932 WARN〜SQL错误:0,SQLState:08S01 
2012-04-13T23:00:44 + 00:00 app [web.1]:23:00:44,932错误〜通信链接失败
2012-04-13T23:00:44 + 00:00应用[web.1]:
2012-04-13T23: 00:44 + 00:00 app [web.1]:从服务器成功接收的最后一个数据包是274,847毫秒前。成功发送到服务器的最后一个数据包是7毫秒前。
2012-04-13T23:00:44 + 00:00 app [web.1]:23:00:44,934错误〜为什么司机在这里抱怨?
2012-04-13T23:00:44 + 00:00 app [web.1]:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:连接关闭后,不允许任何操作。连接被驱动程序隐式关闭。
2012-04-13T23:00:44 + 00:00 app [web.1]:at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
2012-04-13T23 :00:44 + 00:00 app [web.1]:at com.mysql.jdbc.Util.getInstance(Util.java:382)
2012-04-13T23:00:44 + 00:00 app [web.1]:at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
2012-04-13T23:00:44 + 00:00 app [web.1]:at com。 mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
2012-04-13T23:00:44 + 00:00 app [web.1]:at com.mysql.jdbc.SQLError.createSQLException(SQLError .java:982)
2012-04-13T23:00:44 + 00:00 app [web.1]:at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
2012-04-13T23:00:44 + 00:00 app [web.1]:at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1213)
2012-04-13T23:00:44 +00:00 app [web.1]:at com.mysql.jdbc.ConnectionImpl.getMutex(ConnectionImpl.java:3101)
2012-04-13T23:00:44 + 00:00 app [web.1 ]:在com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:497 5)
2012-04-13T23:00:44 + 00:00 app [web.1]:at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
2012-04 -13T23:00:44 + 00:00 app [web.1]:at $ Proxy49.setAutoCommit(Unknown Source)
2012-04-13T23:00:44 + 00:00 app [web.1]:在play.db.jpa.JPAPlugin.closeTx(JPAPlugin.java:368)
2012-04-13T23:00:44 + 00:00 app [web.1]:在play.db.jpa.JPAPlugin。 onInvocationException(JPAPlugin.java:328)
2012-04-13T23:00:44 + 00:00 app [web.1]:at play.plugins.PluginCollection.onInvocationException(PluginCollection.java:447)
2012-04-13T23:00:44 + 00:00 app [web.1]:at play.Invoker $ Invocation.onException(Invoker.java:240)
2012-04-13T23:00:44+ 00:00 app [web.1]:at play.jobs.Job.onException(Job.java:124)
2012-04-13T23:00:44 + 00:00 app [web.1]:at play.jobs.Job.call(Job.java:163)
2012-04-13T23:00:44 + 00:00 app [web.1]:在play.jobs.Job $ 1.call(Job。 java:66)
2012-04-13T23:00:44 + 00:00 app [web.1]:位于java.util.concurrent.FutureTask $ Sync.inne rRun(FutureTask.java:334)
2012-04-13T23:00:44 + 00:00 app [web.1]:at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2012-04-13T23:00:44 + 00:00 app [web.1]:位于java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 101(ScheduledThreadPoolExecutor.java:165)
2012-04 -13T23:00:44 + 00:00 app [web.1]:在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)
2012-04-13T23:00:44+ 00:00 app [web.1]:在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
2012-04-13T23:00:44 + 00:00 app [web.1] :在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
2012-04-13T23:00:44 + 00:00 app [web.1]:at java.lang.Thread .run(Thread.java:636)
2012-04-13T23:00:44 + 00:00 app [web.1]:导致:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败


解决方案

它适用于我。



我认为application.conf中的'db.pool'只读了一些选项,看看播放源代码( DBPlugin.onApplicationStart()):

  ComboPooledDataSource ds = new ComboPooledDataSource(); 
ds.setDriverClass(p.getProperty(db.driver));
ds.setJdbcUrl(p.getProperty(db.url));
ds.setUser(p.getProperty(db.user));
ds.setPassword(p.getProperty(db.pass));
ds.setAcquireRetryAttempts(10);
ds.setCheckoutTimeout(Integer.parseInt(p.getProperty(db.pool.timeout,5000)));
ds.setBreakAfterAcquireFailure(false);
ds.setMaxPoolSize(Integer.parseInt(p.getProperty(db.pool.maxSize,30)));
ds.setMinPoolSize(Integer.parseInt(p.getProperty(db.pool.minSize,1)));
ds.setMaxIdleTimeExcessConnections(Integer.parseInt(p.getProperty(db.pool.maxIdleTimeExcessConnections,0)));
ds.setIdleConnectionTestPeriod(10);
ds.setTestConnectionOnCheckin(true);


I'm trying to customize my C3P0 settings to avoid the error shown at the bottom of this post.

It was suggested at this url --- http://make-it-open.blogspot.com/2008/12/sql-error-0-sqlstate-08s01.html --- to adjust the settings as follows:

In hibernate.cfg.xml, write

<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>

Then create "c3p0.properties" in your root classpath folder and write

c3p0.testConnectionOnCheckout=true
c3p0.acquireRetryDelay=1000
c3p0.acquireRetryAttempts=1

I've tried to make those adjustments following the direction of the Play! Framework documentation, where they say use "db.pool..." as follows:

db.pool.timeout=1800
db.pool.maxSize=15
db.pool.minSize=5
db.pool.initialSize=5
db.pool.acquireRetryAttempts=1
db.pool.preferredTestQuery=SELECT 1
db.pool.testConnectionOnCheckout=true
db.pool.acquireRetryDelay=1000 
db.pool.maxStatements=50

Are those settings not going to work? Should I be trying to set them in a different way? With those settings I still get the error shown below, that is due to to long of a idle time.

Complete Stack Trace of Error:

23:00:44,932 WARN  ~ SQL Error: 0, SQLState: 08S01
2012-04-13T23:00:44+00:00 app[web.1]: 23:00:44,932 ERROR ~ Communications link failure
2012-04-13T23:00:44+00:00 app[web.1]: 
2012-04-13T23:00:44+00:00 app[web.1]: The last packet successfully received from the server was 274,847 milliseconds ago.  The last packet sent successfully to the server was 7 milliseconds ago.
2012-04-13T23:00:44+00:00 app[web.1]: 23:00:44,934 ERROR ~ Why the driver complains here?
2012-04-13T23:00:44+00:00 app[web.1]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed by the driver.
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.Util.getInstance(Util.java:382)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1213)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.ConnectionImpl.getMutex(ConnectionImpl.java:3101)
2012-04-13T23:00:44+00:00 app[web.1]:   at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4975)
2012-04-13T23:00:44+00:00 app[web.1]:   at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
2012-04-13T23:00:44+00:00 app[web.1]:   at $Proxy49.setAutoCommit(Unknown Source)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.db.jpa.JPAPlugin.closeTx(JPAPlugin.java:368)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.db.jpa.JPAPlugin.onInvocationException(JPAPlugin.java:328)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.plugins.PluginCollection.onInvocationException(PluginCollection.java:447)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.Invoker$Invocation.onException(Invoker.java:240)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.jobs.Job.onException(Job.java:124)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.jobs.Job.call(Job.java:163)
2012-04-13T23:00:44+00:00 app[web.1]:   at play.jobs.Job$1.call(Job.java:66)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.FutureTask.run(FutureTask.java:166)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:165)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
2012-04-13T23:00:44+00:00 app[web.1]:   at java.lang.Thread.run(Thread.java:636)
2012-04-13T23:00:44+00:00 app[web.1]: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

解决方案

Create "c3p0.properties" inside 'conf' dir.

It works for me.

I think that 'db.pool' at application.conf only read a few options, take a look at play source code ( DBPlugin.onApplicationStart() ):

ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass(p.getProperty("db.driver"));
ds.setJdbcUrl(p.getProperty("db.url"));
ds.setUser(p.getProperty("db.user"));
ds.setPassword(p.getProperty("db.pass"));
ds.setAcquireRetryAttempts(10);
ds.setCheckoutTimeout(Integer.parseInt(p.getProperty("db.pool.timeout", "5000")));
ds.setBreakAfterAcquireFailure(false);
ds.setMaxPoolSize(Integer.parseInt(p.getProperty("db.pool.maxSize", "30")));
ds.setMinPoolSize(Integer.parseInt(p.getProperty("db.pool.minSize", "1")));
ds.setMaxIdleTimeExcessConnections(Integer.parseInt(p.getProperty("db.pool.maxIdleTimeExcessConnections", "0")));
ds.setIdleConnectionTestPeriod(10);
ds.setTestConnectionOnCheckin(true);

这篇关于玩!框架1.2.4 --- C3P0设置避免通信链路故障做空闲时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆