From 43212e22e2db0b92bdad52717094c9a6005e1194 Mon Sep 17 00:00:00 2001 From: Diego Ruiz Date: Wed, 13 Nov 2019 14:55:29 +0100 Subject: [PATCH] IDEMPIERE-3043 by synchronized. sometime, get list service will wrong --- .../plugin/utils/AbstractActivator.java | 19 ++++++++++++++----- .../utils/PackInApplicationActivator.java | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java index c8b3144605..e13249a085 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AbstractActivator.java @@ -49,7 +49,8 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack private String trxName = null; private ProcessInfo m_processInfo = null; private IProcessUI m_processUI = null; - public static boolean isFrameworkCompletedSrart = false; + private final static Object mutex = new Object(); + private static boolean isFrameworkStarted = false; @Override @@ -58,7 +59,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " starting..."); serviceTracker = new ServiceTracker(context, IDictionaryService.class.getName(), this); serviceTracker.open(); - if (!isFrameworkCompletedSrart) + if (!isFrameworkStarted()) context.addFrameworkListener(this); start(); if (logger.isLoggable(Level.INFO)) logger.info(getName() + " " + getVersion() + " ready."); @@ -216,11 +217,19 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack @Override public void frameworkEvent(FrameworkEvent event) { if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED) { - isFrameworkCompletedSrart = true; - frameworkStarted(); + synchronized(mutex) { + isFrameworkStarted = true; + frameworkStarted(); + } } } + public static Boolean isFrameworkStarted() { + synchronized(mutex) { + return isFrameworkStarted; + } + } + protected abstract void frameworkStarted(); /** @@ -243,7 +252,7 @@ public abstract class AbstractActivator implements BundleActivator, ServiceTrack public IDictionaryService addingService( ServiceReference reference) { service = context.getService(reference); - if (isFrameworkCompletedSrart) + if (isFrameworkStarted()) frameworkStarted (); return null; } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java index 9008eda0e7..5666eafabd 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java @@ -26,7 +26,6 @@ import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; -import org.adempiere.base.IDictionaryService; import org.adempiere.util.ServerContext; import org.compiere.Adempiere; import org.compiere.model.MClient; @@ -41,7 +40,6 @@ import org.compiere.util.AdempiereSystemError; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Util; -import org.osgi.framework.ServiceReference; public class PackInApplicationActivator extends AbstractActivator{