Migliorie allo shutdown di Tomcat
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -21,7 +21,7 @@ public class ExecutorServiceConfig {
|
||||
return new ThreadPoolExecutor(
|
||||
corePoolSize,
|
||||
maxPoolSize,
|
||||
60L,
|
||||
5,
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(queueSize),
|
||||
new ThreadFactoryBuilder()
|
||||
|
||||
@@ -69,10 +69,9 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -5,15 +5,14 @@ import it.integry.ems.looper.dto.LoopDTO;
|
||||
import it.integry.ems.looper.dto.TaskModel;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
@Component
|
||||
public class LooperService implements ApplicationListener<ContextClosedEvent> {
|
||||
public class LooperService {
|
||||
private final ArrayList<LoopDTO> mLoopsHandler = new ArrayList<>();
|
||||
private final ArrayList<TaskModel> mLoopsTask = new ArrayList<>();
|
||||
|
||||
@@ -43,22 +42,23 @@ public class LooperService implements ApplicationListener<ContextClosedEvent> {
|
||||
return newId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
if (!isShuttingDown) {
|
||||
isShuttingDown = true;
|
||||
// @Override
|
||||
// public void onApplicationEvent(ContextClosedEvent event) {
|
||||
// if (!isShuttingDown) {
|
||||
// isShuttingDown = true;
|
||||
//
|
||||
// logger.info("Cleaning up LooperService");
|
||||
// try {
|
||||
// destroy();
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
logger.info("Cleaning up LooperService");
|
||||
try {
|
||||
destroy();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() throws Exception {
|
||||
logger.trace("Destroying " + mLoopsHandler.size() + " looping threads");
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
logger.info("Shutting down LooperService (" + mLoopsHandler.size() + " threads)");
|
||||
|
||||
for (int i = 0; i < mLoopsTask.size(); i++) {
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.object_storage.interfaces.IObjectStorageService;
|
||||
import it.integry.ems.settings.Model.MinIOSettingsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -19,14 +20,12 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -119,8 +118,24 @@ public class MinIOService implements IObjectStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
logger.info("Destroying MinIO connection");
|
||||
this.disconnect();
|
||||
logger.info("MinIO connection destroyed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
|
||||
if(mMinioClient != null) {
|
||||
try {
|
||||
mMinioClient.close();
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
this.mMinioClient = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,13 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -43,6 +47,14 @@ public class BasicConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
logger.info("Shutting down connection pool");
|
||||
closeAllConnections();
|
||||
logger.info("Connection pool shut down successfully");
|
||||
}
|
||||
|
||||
|
||||
private void closeAllConnections() {
|
||||
poolLock.lock();
|
||||
try {
|
||||
|
||||
@@ -3,14 +3,14 @@ package it.integry.ems.task;
|
||||
import com.itextpdf.text.log.Logger;
|
||||
import com.itextpdf.text.log.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@Service
|
||||
@Component
|
||||
public class TaskExecutorService {
|
||||
|
||||
@Autowired
|
||||
@@ -73,7 +73,7 @@ public class TaskExecutorService {
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
public void destroy() {
|
||||
try {
|
||||
logger.info("Initiating shutdown of ExecutorService");
|
||||
executorService.shutdown();
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
|
||||
<!-- NB: DICHIARAZIONE DELLO SCHEDULER PER IL CARICAMENTO DINAMICO DEI MODULI ABILITATI -->
|
||||
<bean id="quartzScheduler"
|
||||
class="it.integry.ems.scheduler.CustomSchedulerFactoryBean">
|
||||
class="it.integry.ems.scheduler.CustomSchedulerFactoryBean" destroy-method="destroy">
|
||||
|
||||
<property name="configLocation" value="classpath:quartz/config.properties"/>
|
||||
<property name="autoStartup" value="true"/>
|
||||
|
||||
Reference in New Issue
Block a user