In order to simulate a database outage our DBAs turned off the relevant service account and killed all existing connections while our server was running. We then discovered that the answer to my own question, for the benefit of others, is that a JdbcTemplate will not automatically recover without the correct configuration.
My initial config was as follows:
<bean id="DataSource" class="oracle.ucp.jdbc.PoolDataSourceFactory" factory-method="getPoolDataSource">
<property name="URL" value="${jdbc.url}"/>
<property name="User" value="${jdbc.user}"/>
<property name="Password" value="${jdbc.password}"/>
<property name="ConnectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="ConnectionPoolName" value="FOX"/>
<property name="MinPoolSize" value="1"/>
<property name="MaxPoolSize" value="3"/>
<property name="InitialPoolSize" value="1"/>
</bean>
<bean id="DataTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="DataSource" />
</bean>
Unfortunately, in the case of an outage, this leaves dead connections in your pool, hence, our server did not recover. I imagine there are a number of different ways you could resolve this, possibly by purging the pool when you see an exception for example, however, setting ValidateConnectionOnBorrow
to true
was a simple change and had the desired effect:
<bean id="DataSource" class="oracle.ucp.jdbc.PoolDataSourceFactory" factory-method="getPoolDataSource">
<property name="URL" value="${jdbc.url}"/>
<property name="User" value="${jdbc.user}"/>
<property name="Password" value="${jdbc.password}"/>
<property name="ConnectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="ConnectionPoolName" value="FOX"/>
<property name="MinPoolSize" value="1"/>
<property name="MaxPoolSize" value="3"/>
<property name="InitialPoolSize" value="1"/>
<property name="ValidateConnectionOnBorrow" value="true"/>
</bean>
<bean id="DataTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="DataSource" />
</bean>
Now our pooled connetions are validated and when an outage occurs the broken connections are disposed. As a result, once the database recovered, our server was back online.