grails oracle连接超时

时间:2015-06-22 18:19:02

标签: grails gorm

我在grails中有数据源配置。

dataSource_staging_oracle {
    dbCreate = "none"
    pooled = true
    url = "jdbc:oracle:thin:@//my-box-oracle.com:1521/DB1"
    driverClassName = "oracle.jdbc.OracleDriver"
    username = "USER_1"
    password = "encryptedpassword"
    passwordEncryptionCodec = PropertiesCodec
}
dataSource_prod_oracle {
    dbCreate = "none"
    pooled = true
    autoReconnect = true
    url = "jdbc:oracle:thin:@//my-oracle-prod-box.com:1521/DB2"
    driverClassName = "oracle.jdbc.OracleDriver"
    username = "user_2"
    password = "encrypted_password"
    passwordEncryptionCodec = PropertiesCodec
}

应用程序能够获取数据库连接并正常工作。但是经过1-2个小时的处理后,我看到连接已关闭异常。

 ERROR util.JDBCExceptionReporter  - Closed Connection

我认为这与数据源配置属性有关。什么grails设置可以帮助我刷新连接?我已将autoReconnectpooled设置为true

我使用grails 2.3.3

2 个答案:

答案 0 :(得分:1)

数据源属性将通知数据库中间件服务器对数据库的期望。如果您的Oracle服务器不同意Grails想要使用的设置,那么有时会出现含糊不清的错误消息。

使用池化连接告诉Oracle为应用程序保留许多连接。如果应用程序运行1-2小时并持续处理,我预计池可能会用完有效的连接。有些背景请查看下面的链接。

查看Grails configuration docs,第4.4节,查看高级数据源配置选项。您是否定义了验证查询? (例如select 1 from dual;

查看此AskTom帖子,了解connection pooling的详细解释。

带有MySQL的

Previous StackOverflow question但类似的错误。

答案 1 :(得分:0)

下面的配置帮助我解决了我的问题。

dataSource_staging {
            dbCreate = "none"
            pooled = true
            autoReconnect = true
            url = "jdbc:oracle:thin:@//my-box-oracle.com:1521/DB1"
            driverClassName = "oracle.jdbc.OracleDriver"
            username = "USER_1"
            password = "encryptedpassword"
            passwordEncryptionCodec = PropertiesCodec
            properties {
                validationQuery = "SELECT 1 FROM DUAL"
                testOnBorrow = true
                testWhileIdle = true
                testOnReturn = false
                timeBetweenEvictionRunsMillis = 5000
                minEvictableIdleTimeMillis = 60000
                maxAge = 10 * 60000
                maxWait = 10000
                maxIdle = 25
                maxActive = 50
                initialSize = 5
            }
        }