如何删除C3P0设置生成的TIMED_WAITING线程 [英] How to remove TIMED_WAITING threads generated by C3P0 settings

查看:107
本文介绍了如何删除C3P0设置生成的TIMED_WAITING线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c3p0集成方面是一个非常新的人...

I am very new in c3p0 integration...

我在 c3p0-0.9.5-pre5.jar中进行了这些设置 hibernate-c3p0-3.5.6-Final.jar hibernate-core-3.5.6-Final.jar mchange-commons-java-0.2.6.3.jar 罐子如下...

I have these settings with c3p0-0.9.5-pre5.jar, hibernate-c3p0-3.5.6-Final.jar, hibernate-core-3.5.6-Final.jar and mchange-commons-java-0.2.6.3.jar jars like below...

    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

    <property name="hibernate.c3p0.min_size">1</property>
    <property name="hibernate.c3p0.max_size">5</property>
    <property name="hibernate.c3p0.timeout">40</property> 
    <property name="hibernate.c3p0.idle_test_period">30</property> 
    <!--<property name="hibernate.c3p0.max_statements">50</property>-->
    <property name="hibernate.c3p0.maxStatementsPerConnection">5</property> <!--Instead of max_statements-->
    <property name="hibernate.c3p0.validate">true</property>

    <property name="hibernate.connection.pool_size">25</property>
    <property name="hibernate.c3p0.acquire_increment">1</property>
    <property name="hibernate.c3p0.automaticTestTable">con_test</property>
    <property name="hibernate.c3p0.privilegeSpawnedThreads">true</property>
    <property name="hibernate.c3p0.contextClassLoaderSource">library</property>
    <property name="hibernate.c3p0.maxAdministrativeTaskTime">30</property>
    <property name="hibernate.c3p0.numHelperThreads">20</property>

问题是,应用程序生成数千个线程并将其保留为时间等待线程。

The problem is, application generates thousands of threads and keep those as Time waited Threads.

我已经循环打印了其中一些线程..

I have print some of those threads by a loop ..

"<br/>" + c++ +". "+ t.getState() + " (" + t.isAlive() + ") : " + t.getName();

结果低于...

    147. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|2feccbb3]-HelperThread-#0
    148. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|8d0e89c]-HelperThread-#3
    149. WAITING (true) : Reference Handler
    150. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|8d0e89c]-HelperThread-#2
    151. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|1045f6be]-HelperThread-#8
    152. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|1045f6be]-HelperThread-#19
    153. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|3b0c81d2]-HelperThread-#17
    154. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|2feccbb3]-HelperThread-#3
    155. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|2feccbb3]-HelperThread-#1
    156. TIMED_WAITING (true) : C3P0PooledConnectionPoolManager[identityToken->1hge86f9r1gp0vs6si1few|70cef37d]-HelperThread-#19

首先是通过应用程序从数据库中检索数据。

This is increasing very first when retrieve data from database by application.

由Java,Struts-1,Hibernate,Oracle(BD)开发的应用程序。

App developed by Java, Struts-1, Hibernate, Oracle(BD).

如何删除/杀死这些线程

推荐答案

一种方法或其他方法,如果您看到数千个这些线程,则说明您泄漏了数据源。也就是说,您的应用程序正在构造c3p0数据源,每个数据源都有自己的线程补充,然后丢失或取消引用或替换它们而没有先 close()对其进行处理。

One way or some other, if you are seeing thousand of these Threads, you are leaking DataSources. That is, your application is constructing c3p0 DataSources, each of which has its own complement of Threads, then it is losing or dereferencing or replacing them without first close()ing them.

池化的DataSource应该构造一次,放置在具有共享可用性的位置,然后反复使用。如果由于某种原因需要重新构造数据源,则需要 close() c3p0数据源,否则它们的线程将永远存在。

A pooled DataSource should be constructed once, placed somewhere with shared availability, and reused over and over again. If, unusually, a DataSource needs to be reconstructed for some reason, you need to close() c3p0 DataSources or their Threads will live forever.

也许导致这种情况的最常见错误是热重新部署的应用程序。如果在应用程序初始化时创建了DataSource,则在重新部署周期的关闭挂钩中,您必须开车破坏相同的DataSource。

Perhaps the most common error that leads to this sort of thing are applications that hot-redeploy. If on app initialization a DataSource is created, in a shutdown hook in the redeploy cycle you must take car that the same DataSource gets destroyed.

请注意,在上面的线程列表中,您显示了许多来自不同数据源的线程(因为它们在 | 之前的公共VMID部分之后具有不同的标识令牌)。您肯定是在创建而不是 close()大量的数据源。

Note that in the list of Threads above, you show many Threads from different DataSources (as they have different identity tokens after the common VMID portion before the |). You are definitely creating but not close()ing lots of DataSources.

这篇关于如何删除C3P0设置生成的TIMED_WAITING线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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