/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.parallax.server.common.cloudsession.service.impl;

import com.google.inject.Inject;
import com.parallax.server.common.cloudsession.db.dao.UserDao;
import com.parallax.server.common.cloudsession.service.DatabaseMaintenanceService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author Michel
 */
public class DatabaseMaintenanceServiceImpl implements DatabaseMaintenanceService, Runnable {

    private ScheduledExecutorService service;

    private UserDao userDao;

    @Inject
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
        setup();
    }

    public void setup() {
        this.service = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setDaemon(true);
                return thread;
            }
        });
        this.service.scheduleAtFixedRate(this, 5, 5, TimeUnit.MINUTES);
    }

    @Override
    public void run() {
        userDao.count();
    }

}

@@ -593,16 +593,73 @@
 imeUnit;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -776,16 +776,105 @@
 able %7B%0A%0A
+    private Logger log = LoggerFactory.getLogger(DatabaseMaintenanceServiceImpl.class);%0A%0A
     priv
@@ -1488,16 +1488,47 @@
 %0A       
+ log.info(%22Keep db active: %7B%7D%22,
  userDao
@@ -1535,16 +1535,17 @@
 .count()
+)
 ;%0A    %7D%0A

Fix sleeping database connection bug