Announcement Announcement Module
Collapse
No announcement yet.
RecoverableDataAccessException: last packet was xxx seconds ago... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RecoverableDataAccessException: last packet was xxx seconds ago...

    Hopefully someone has an answer for this one. I'm using Spring's JdbcTemplate to do a few queries from within a background batch job that runs on a nightly basis. The problem is that after a day or two, the connection goes bad and it cannot be used without restarting the application server.

    This is the exception I am getting:
    org.springframework.dao.RecoverableDataAccessExcep tion: PreparedStatementCallback; The last packet successfully received from the server was86375 seconds ago.The last packet sent successfully to the server was 86376 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ption: The last packet successfully received from the server was86375 seconds ago.The last packet sent successfully to the server was 86376 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    I have a simple database connection I am using in JdbcTemplate which is configured like so in my applicationContext.xml:
    Code:
    <bean id="partnerDataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="jdbc:mysql://192.168.1.15:3306/mydb?autoReconnect=true" />
            <property name="url" value="${jdbc.partnerUrl}" />
            <property name="username" value="${jdbc.partnerUsername}" />
            <property name="password" value="${jdbc.partnerPassword}" />
        </bean>
    The background job is a quartz scheduled job. I doubt the details are important. The scheduled job bean calls a service which is marked as transactional.

    Scheduled Job:
    Code:
    @Configurable
    public class PartnerDataProcessor extends QuartzJobBean {
    	
    	private static final long serialVersionUID = 1L;
    	private final Logger log = Logger.getLogger(getClass());
    	
    	private boolean run = false;
    	
    	@Resource 
    	private RollupBatchService rollupBatchService;
    	
    	protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
    		
    		if (run) {		
    			
    			try {
    				rollupBatchService.runBatchRollups();
    			} catch (Exception e) {
    				log.fatal("ROLLUP SERVICE - Error processing partner data: " + e);
    			}
    		}
    	}
    
    	public boolean isRun() { return run; }
    	public void setRun(boolean run) { this.run = run; }
    }
    The rollupBatchService is marked as @Transactional:
    Code:
    @Repository("partnerDataBatchService")
    @Transactional
    public class RollupBatchServiceImpl implements RollupBatchService {
    	
    	private static final long serialVersionUID = 1L;
    	private final Logger log = Logger.getLogger(getClass());
    	
    	private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    	
    	@PersistenceContext
    	private EntityManager em;
    	
    	@Resource 
    	private PartnerQueryService partnerQueryService;
    	
    	@Resource
    	private TimecardService timecardService;
    	
    	/* (non-Javadoc)
    	 * @see com.lf.service.partner.RollupBatchService#runBatchRollups()
    	 */
    	public void runBatchRollups() throws LFException {
    		// Do stuff with partnerQueryService and em here.
    	}
    }
    Does anyone have any idea why I would be getting this exception after a long period of time? Shouldn't JdbcTemplate be closing the connection, and creating a new one the next time it is used?

    Thanks for any help.
Working...
X