重启服务器后c3p0上的连接问题

时间:2015-07-06 09:48:17

标签: hibernate oracle11g c3p0

我在我的应用程序中使用c3p0进行Hibernate与Oracle数据库的连接。我们有两台并行运行的服务器。通常工作正常,但重新启动后,其中一个服务器在尝试通过c3p0连接到DB时出现异常。抛出的根异常是

buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
    }
}

apply plugin: 'forge'

version = “1”
group = “com.candymod.mincoder”
archivesBaseName = “Candymod”

minecraft {
    version = "1.7.10-10.13.2.1230"
    runDir = "eclipse"
}

dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"

    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

    // for more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html

}

processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }

    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

再次重启后,服务器行为正常。我正在使用hibernate-c3p0-4.3.6.Final。

这是我的c3p0连接配置

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    ... 53 more

有没有人经历过类似的行为?

1 个答案:

答案 0 :(得分:0)

这是可重复的吗?如果不是,我猜这是两个问题之一:

  1. 创建与数据库的连接时确实存在问题。如果我没有正确地记住Oracle,现有连接可以很好地工作,但是新的连接不能被创建,例如当监听器服务变得不可用时。

  2. 或者在启动期间某些进程耗尽了所有可用的连接。例如,当某个队列的进程启动时,以及队列的停机时间已满,可能会发生这种情况。请注意,连接限制可能是在连接池中配置的连接限制,也可能是在oracle数据库中配置的连接限制。