【问题标题】:How to initialize c3po connection pool on application launch?如何在应用程序启动时初始化 c3po 连接池?
【发布时间】:2021-03-29 08:15:37
【问题描述】:

c3p0连接池在我执行一些JPA操作时初始化,初始化需要2秒。

    <property name="hibernate.c3p0.min_size">10</property>
    <property name="hibernate.c3p0.max_size">30</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.idle_test_period">150</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.privilegeSpawnedThreads">true</property>
    <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>  

那么有没有办法在应用程序启动时做到这一点?

【问题讨论】:

    标签: hibernate jpa c3p0


    【解决方案1】:

    在应用程序启动时执行操作。

    如果你的 c3p0 DataSource 被称为 myPool,那么 myPool.getConnection().close() 就足够了。

    【讨论】:

    • 我已经在 hibernate.cfg 中配置了它,所以可以使用 hibernate.cfg 吗?我的意思是在 hibernate.cfg 中配置了现有连接的数据源。
    猜你喜欢
    • 2013-01-12
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2011-11-17
    • 2018-04-25
    • 2016-12-13
    • 2020-09-20
    • 2011-12-03
    相关资源
    最近更新 更多