Lately I get trouble because my database service is often restart and makes connection from glashfish server to that database become failure. The aftermath is every EJB timer which need connection to the database didn’t fulfill it purpose or raise exception. Restart glashfish everytime database service restarted to regain connection is tiresome solution.

After attempt varying glashfish connectionPool setting, I found an setting that should applied to make connectionPool able to regain it connection to database service automatically.
Here is settings that need to change/add :
  • is-connection-validation-required=”true”
  • idle-timeout-in-seconds=”300″
  • connection-creation-retry-attempts=”2″
  • connection-validation-method=”table”
  • validation-table-name=”myTable”
  • property.dynamic-reconfiguration-wait-timeout-in-seconds=”15″

NB : validation-table-name should be filled by table which not often change or doesn’t have much record/row.

<?xml version="1.0" encoding="UTF-8"?>
<!--Meihta Dwiguna Saputra-->
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-connection-pool
allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="2"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="table"
datasource-classname="org.postgresql.ds.PGSimpleDataSource"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="true"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="myConnectionPool"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource"
statement-timeout-in-seconds="-1"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
validation-table-name="myTable"
wrap-jdbc-objects="false">
<property name="URL" value="jdbc:postgresql://localhost:5432/myDatabase"/>
<property name="User" value="server"/>
<property name="Password" value="server"/>
<property name="DatabaseName" value="myDatabase"/>
<property name="driverClass" value="org.postgresql.Driver"/>
<property name="dynamic-reconfiguration-wait-timeout-in-seconds" value="15"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="myJndi" object-type="user" pool-name="myConnectionPool"/>
</resources>

Hope the post useful, thanks for reading.🙂
Subscribe & fast response :