随笔-35  评论-33  文章-0  trackbacks-0
  2017年6月29日

      已经一个多月没有写东西了,不过最近确实很忙。前两天在线上碰到一个C3P0的链接死锁的异常,话说这个上古神物 ,我已经是很久不碰了。先贴异常



异常截图

"apparent deadlocks":名词解释是说c3p0拿到链接之后,最终使用之后没有返回到pool,导致死链检测失败。经过在stack Overflow检索,https://stackoverflow.com/questions/3730844/c3p0-apparent-deadlock-when-the-threads-are-all-empty.发现增加一个statementCacheNumDeferredCloseThreads该参数的定义,就可以避免这个问题。

经过查看官方文档:http://www.mchange.com/projects/c3p0/#statementCacheNumDeferredCloseThreads



解释:如果把该值设为超过1,statement的缓存就会自动跟踪当前可用的connections,如果没有再用,就会自动销毁掉。如果需要另外的线程来专门销毁缓存的statement,则还需要设置maxStatements与maxStatementsPerConnection。

再贴一个官方的说明:

Configuring Statement Pooling

c3p0 implements transparent PreparedStatement pooling as defined by the JDBC spec. Under some circumstances, statement pooling can dramatically improve application performance. Under other circumstances, the overhead of statement pooling can slightly harm performance. Whether and how much statement pooling will help depends on how much parsing, planning, and optimizing of queries your databases does when the statements are prepared. Databases (and JDBC drivers) vary widely in this respect. It's a good idea to benchmark your application with and without statement pooling to see if and how much it helps.

You configure statement pooling in c3p0 via the following configuration parameters:

maxStatements

maxStatementsPerConnection

statementCacheNumDeferredCloseThreads

maxStatementsis JDBC's standard parameter for controlling statement pooling.maxStatementsdefines the total numberPreparedStatementsa DataSource will cache. The pool will destroy the least-recently-used PreparedStatement when it hits this limit. This sounds simple, but it's actually a strange approach, because cached statements conceptually belong to individual Connections; they are not global resources. To figure out a size formaxStatementsthat does not "churn" cached statements, you need to consider the number offrequently usedPreparedStatements in your application,and multiply that by the number of Connections you expect in the pool (maxPoolSizein a busy application).

maxStatementsPerConnectionis a non-standard configuration parameter that makes a bit more sense conceptually. It defines how many statements each pooled Connection is allowed to own. You can set this to a bit more than the number ofPreparedStatementsyour applicationfrequentlyuses, to avoid churning.

If either of these parameters are greater than zero, statement pooling will be enabled. If both parameters are greater than zero, both limits will be enforced. If only one is greater than zero, statement pooling will be enabled, but only one limit will be enforced.

大概意思就是这两个,有一个值如果大于0,c3p0的statement pool就会发生作用。

以上所有的配置都是基于c3p0的最新版本。PS一下,还是2015年的JAR。



通过引入最新的C3P0包,另外增加了两段配置,线上观察两天,问题解决。



最后打个小广告,JAVA世界最快的JDBC连接池,非HikariCP莫属。已经甩c3p0好几个街角,有图有真像。



posted @ 2017-11-10 15:25 alexcai 阅读(1782) | 评论 (0)编辑 收藏
     摘要: 在word的处理之中,文字,各种类型的图片,最复杂的公式,之前编写的API基本都覆盖了。不过,昨天在做一个文档测试时,发现表格没有能很好的处理。  阅读全文
posted @ 2017-08-25 15:54 alexcai 阅读(745) | 评论 (0)编辑 收藏
     摘要: HDFS和MapReduce是Hadoop的两大核心,除此之外Hbase、Hive这两个核心工具也随着Hadoop发展变得越来越重要。今天我们只初步的看看HDFS.  阅读全文
posted @ 2017-07-24 10:35 alexcai 阅读(649) | 评论 (0)编辑 收藏
     摘要: 使用thrift已经有段时间了,目前基本是clien+server的方式,负载是通过nginx来处理。这种处理方式有两个比较大的弊端:  阅读全文
posted @ 2017-06-29 16:39 alexcai 阅读(865) | 评论 (0)编辑 收藏