From 7167519190676e6507cf2d62d6c6b15d5d2ca9c1 Mon Sep 17 00:00:00 2001 From: Kamil Jarmusik Date: Thu, 9 May 2024 18:59:33 +0200 Subject: [PATCH] #2083 Catching an exception in an application initialization method: - Application startup event generation postponed after application initialization; - Stopping WorkItemMonitor if the application is not started; --- src/com/serotonin/mango/MangoContextListener.java | 11 ++++++----- src/com/serotonin/mango/rt/maint/WorkItemMonitor.java | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/com/serotonin/mango/MangoContextListener.java b/src/com/serotonin/mango/MangoContextListener.java index bce8617457..34d6befc09 100644 --- a/src/com/serotonin/mango/MangoContextListener.java +++ b/src/com/serotonin/mango/MangoContextListener.java @@ -92,6 +92,11 @@ public class MangoContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent evt) { try { initialized(evt); + // Notify the event manager of the startup. + SystemEventType.raiseEvent(new SystemEventType( + SystemEventType.TYPE_SYSTEM_STARTUP), System + .currentTimeMillis(), false, new LocalizableMessage( + "event.system.startup")); } catch (Exception ex) { log.error(ex.getMessage(), ex); throw ex; @@ -163,11 +168,7 @@ private void initialized(ServletContextEvent evt) { scriptContextInitialize(); - // Notify the event manager of the startup. - SystemEventType.raiseEvent(new SystemEventType( - SystemEventType.TYPE_SYSTEM_STARTUP), System - .currentTimeMillis(), false, new LocalizableMessage( - "event.system.startup")); + try { diff --git a/src/com/serotonin/mango/rt/maint/WorkItemMonitor.java b/src/com/serotonin/mango/rt/maint/WorkItemMonitor.java index 157fcfea8f..8043a1dca3 100644 --- a/src/com/serotonin/mango/rt/maint/WorkItemMonitor.java +++ b/src/com/serotonin/mango/rt/maint/WorkItemMonitor.java @@ -6,9 +6,13 @@ import com.serotonin.mango.Common; import com.serotonin.timer.FixedRateTrigger; import com.serotonin.timer.TimerTask; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.scada_lts.monitor.type.IntegerMonitor; public class WorkItemMonitor extends TimerTask { + + private static final Log LOG = LogFactory.getLog(WorkItemMonitor.class); private static final long TIMEOUT = 1000 * 10; // Run every ten seconds. /** @@ -40,6 +44,11 @@ private WorkItemMonitor() { @Override public void run(long fireTime) { + if(Common.ctx == null || Common.ctx.getBackgroundProcessing() == null) { + LOG.warn("Scada-LTS context terminated"); + return; + } + BackgroundProcessing bp = Common.ctx.getBackgroundProcessing(); mediumPriorityServiceQueueSize.setValue(bp.getMediumPriorityServiceQueueSize());