我无法理解为什么在我的Hibernate应用程序中初始化c3p0连接池需要2分钟.
这是在我的Hibernate.cfg.xml中:
org.postgresql.Driver
org.hibernate.dialect.PostgreSQLDialect
org.hibernate.cache.internal.NoCacheProvider
thread
1
3
10
300
50
3000
true
false
create
在构建会话工厂时,在我的HibernateUtil文件中设置连接设置.
当我的测试中的第一个事务是openend时,池会初始化.
连接和查询数据库之后工作得很好,它只会在下一行挂起一段时间才能启动.我把输出格式化了一下,因为我认为问题可能与这里提到的设置有关:
INFO: Initializing c3p0 pool...
com.mchange.v2.c3p0.PoolBackedDataSource@30670080 [
connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ecfec4d0 [
acquireIncrement -> 1,
acquireRetryAttempts -> 30,
acquireRetryDelay -> 1000,
autoCommitOnClose -> false,
automaticTestTable -> null,
breakAfterAcquireFailure -> false,
checkoutTimeout -> 0,
connectionCustomizerClassName -> null,
connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester,
debugUnreturnedConnectionStackTraces -> false,
factoryClassLocation -> null,
forceIgnoreUnresolvedTransactions -> false,
identityToken -> I-REMOVED-THIS,
idleConnectionTestPeriod -> 3000,
initialPoolSize -> 3,
maxAdministrativeTaskTime -> 0,
maxConnectionAge -> 0,
maxIdleTime -> 300,
maxIdleTimeExcessConnections -> 0,
maxPoolSize -> 10,
maxStatements -> 50,
maxStatementsPerConnection -> 0,
minPoolSize -> 3,
nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@b17e5c65 [
description -> null,
driverClass -> null,
factoryClassLocation -> null,
identityToken -> I-REMOVED-THIS,
jdbcUrl -> jdbc:postgresql://URL-TO-MY_DB,
properties -> {user=******, password=******, default_schema=}
],
preferredTestQuery -> null,
propertyCycle -> 0,
testConnectionOnCheckin -> false,
testConnectionOnCheckout -> false,
unreturnedConnectionTimeout -> 0,
usesTraditionalReflectiveProxies -> false;
userOverrides: {}
],
dataSourceName -> null,
factoryClassLocation -> null,
identityToken -> I-REMOVED-THIS,
numHelperThreads -> 3
]
这是我第一次使用Hibernate和c3p0而且我期望它在启动游戏时更快一些?这是对我的误解吗?
使用远程数据库和本地PostgreSQL实例没有区别.
(编辑:这不是真的.在比较本地和远程数据库服务器时我犯了一个错误.在本地,初始化几乎是立即,远程需要大约2分钟.)
Edit2:Here是连接过程的日志.