Fixed issue 30798. Lots of errors in log during tomcat shutdown related to new import entry project.
authorAntonio Moreno Perez <antonio.moreno@openbravo.com>
Thu, 05 Nov 2015 11:43:28 +0100
changeset 28099 14753c185bd5
parent 27676 bce57079bd43
child 28100 c6bfc013b9d1
Fixed issue 30798. Lots of errors in log during tomcat shutdown related to new import entry project.
src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java
src/org/openbravo/service/importprocess/ImportEntryManager.java
--- a/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Tue Nov 03 05:40:13 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java	Thu Nov 05 11:43:28 2015 +0100
@@ -72,6 +72,8 @@
   private ImportEntryArchiveThread archiveThread;
   private ExecutorService executorService;
 
+  private boolean isShutDown = false;
+
   public ImportEntryArchiveManager() {
     instance = this;
   }
@@ -83,8 +85,10 @@
   }
 
   public void shutdown() {
+    isShutDown = true;
     log.debug("Shutting down Import Entry Archive Framework");
     executorService.shutdownNow();
+    executorService = null;
   }
 
   private static class ImportEntryArchiveThread implements Runnable {
@@ -114,6 +118,11 @@
       Date lastCreated = null;
       while (true) {
         try {
+
+          if (manager.isShutDown) {
+            return;
+          }
+
           boolean dataProcessed = false;
           try {
             // stored is used in the whereclause to make sure that the system will continue
@@ -145,6 +154,10 @@
 
               ImportEntryArchive archiveEntry = createArchiveEntry(importEntry);
 
+              if (manager.isShutDown) {
+                return;
+              }
+
               for (ImportEntryArchivePreProcessor processor : manager.archiveEntryPreProcessors) {
                 processor.beforeArchive(importEntry, archiveEntry);
               }
--- a/src/org/openbravo/service/importprocess/ImportEntryManager.java	Tue Nov 03 05:40:13 2015 +0000
+++ b/src/org/openbravo/service/importprocess/ImportEntryManager.java	Thu Nov 05 11:43:28 2015 +0100
@@ -158,6 +158,8 @@
   // subclass of ImportEntryProcessor going wild
   private int maxTaskQueueSize = 1000;
 
+  private boolean isShutDown = false;
+
   public ImportEntryManager() {
     instance = this;
     importBatchSize = ImportProcessUtils.getCheckIntProperty(log, "import.batch.size",
@@ -221,6 +223,9 @@
    */
   public void shutdown() {
     log.debug("Shutting down Import Entry Framework");
+    
+    isShutDown = true;
+
     executorService.shutdownNow();
     for (ImportEntryProcessor importEntryProcessor : importEntryProcessors.values()) {
       importEntryProcessor.shutdown();
@@ -480,6 +485,11 @@
           }
           try {
 
+            // system is shutting down, bail out
+            if (manager.isShutDown) {
+              return;
+            }
+
             // too busy, don't process, but wait
             if (manager.executorService.getQueue() != null
                 && manager.executorService.getQueue().size() > (manager.maxTaskQueueSize - 1)) {