Configure GlassFish JDBC connection pool to handle Amazon RDS Multi-AZ failover

后端 未结 1 1406
旧巷少年郎
旧巷少年郎 2020-12-30 18:02

I have a Java EE application running in GlassFish on EC2, with a MySQL database on Amazon RDS. I am trying to configure the JDBC connection pool to in order to minimize down

1条回答
  •  礼貌的吻别
    2020-12-30 18:30

    As I commented before, it is because the sockets that are open and connected to the database don't realize the connection has been lost, so they stayed connected until the OS socket timeout is triggered, which I read might be usually in about 30 minutes.

    To solve the issue you need to override the socket Timeout in your JDBC Connection String or in the JDNI COnnection Configuration/Properties to define the socketTimeout param to a smaller time.

    Keep in mind that any connection longer than the value defined will be killed, even if it is being used (I haven't been able to confirm this, is what I read).

    The other two parameters I mention in my comment are connectTimeout and autoReconnect.

    Here's my JDBC Connection String:

    jdbc:(...)&connectTimeout=15000&socketTimeout=60000&autoReconnect=true 
    

    I also disabled Java's DNS cache by doing

     java.security.Security.setProperty("networkaddress.cache.ttl" , "0"); 
     java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0"); 
    

    I do this because Java doesn't honor the TTL's, and when the failover takes place, the DNS is the same but the IP changes.

    Since you are using an Application Server, the parameters to disable DNS cache must be passed to the JVM when starting the glassfish with -Dnet and not the application itself.

    0 讨论(0)
提交回复
热议问题