Merge pull request #1050 from khatwaniNikhil/FIX_Server_Clean_Shutdown
MIFOSX-1501 #comment Fixed Issues related to AbandonedCleanupThread and
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.core.service;
|
||||
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.mysql.jdbc.AbandonedConnectionCleanupThread;
|
||||
|
||||
@Service
|
||||
public class AbandonedConnectionCleanupShutdownListener implements ApplicationListener<ContextStoppedEvent> {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AbandonedConnectionCleanupShutdownListener.class);
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextStoppedEvent event) {
|
||||
shutDowncleanUpThreadAndDeregisterJDBCDriver();
|
||||
}
|
||||
|
||||
private void shutDowncleanUpThreadAndDeregisterJDBCDriver() {
|
||||
try {
|
||||
AbandonedConnectionCleanupThread.shutdown();
|
||||
logger.info("Shut-down of AbandonedConnectionCleanupThread successful");
|
||||
} catch (Throwable t) {
|
||||
logger.error("Exception occurred while shut-down of AbandonedConnectionCleanupThread", t);
|
||||
}
|
||||
|
||||
// This manually deregisters JDBC driver, which prevents Tomcat 7 from
|
||||
// complaining about memory leaks
|
||||
Enumeration<Driver> drivers = DriverManager.getDrivers();
|
||||
while (drivers.hasMoreElements()) {
|
||||
Driver driver = drivers.nextElement();
|
||||
try {
|
||||
java.sql.DriverManager.deregisterDriver(driver);
|
||||
logger.info("JDBC driver de-registered successfully");
|
||||
} catch (Throwable t) {
|
||||
logger.error("Exception occured while deristering jdbc driver", t);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(2000L);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
+2
@@ -19,4 +19,6 @@ public interface JobRegisterService {
|
||||
|
||||
public void stopScheduler(String name);
|
||||
|
||||
public void stopAllSchedulers();
|
||||
|
||||
}
|
||||
|
||||
+19
-1
@@ -35,6 +35,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
|
||||
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
@@ -46,7 +48,7 @@ import org.springframework.stereotype.Service;
|
||||
* {@link CronTriggerFactoryBean}
|
||||
*/
|
||||
@Service
|
||||
public class JobRegisterServiceImpl implements JobRegisterService {
|
||||
public class JobRegisterServiceImpl implements JobRegisterService, ApplicationListener<ContextStoppedEvent> {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(JobRegisterServiceImpl.class);
|
||||
|
||||
@@ -228,6 +230,11 @@ public class JobRegisterServiceImpl implements JobRegisterService {
|
||||
return !this.schedularWritePlatformService.retriveSchedulerDetail().isSuspended();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextStoppedEvent event) {
|
||||
this.stopAllSchedulers();
|
||||
}
|
||||
|
||||
private void scheduleJob(final ScheduledJobDetail scheduledJobDetails) {
|
||||
if (!scheduledJobDetails.isActiveSchedular()) {
|
||||
scheduledJobDetails.updateNextRunTime(null);
|
||||
@@ -251,6 +258,17 @@ public class JobRegisterServiceImpl implements JobRegisterService {
|
||||
scheduledJobDetails.updateCurrentlyRunningStatus(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAllSchedulers() {
|
||||
for (Scheduler scheduler : this.schedulers.values()) {
|
||||
try {
|
||||
scheduler.shutdown();
|
||||
} catch (final SchedulerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Scheduler getScheduler(final ScheduledJobDetail scheduledJobDetail) throws Exception {
|
||||
final String schedulername = getSchedulerName(scheduledJobDetail);
|
||||
Scheduler scheduler = this.schedulers.get(schedulername);
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.loanaccount.data;
|
||||
|
||||
import org.mifosplatform.organisation.monetary.domain.Money;
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.loanaccount.domain;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.loanaccount.loanschedule.domain;
|
||||
|
||||
public class RecalculatedSchedule {
|
||||
|
||||
+5
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.loanaccount.loanschedule.domain;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
Reference in New Issue
Block a user