From 53b31674326871d0fa03f568bf243bb821a2d9b2 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Thu, 1 Aug 2013 13:27:53 +0000 Subject: [PATCH] [BIS-300] Make ApplicationContexts distinguishable on startup and fix thread-safety issue on DssScreeningApplicationContext. SVN: 29602 --- .../dss/generic/shared/ServiceProvider.java | 9 ++++-- .../DssScreeningApplicationContext.java | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java index e2bbcfb0c90..caa44d75121 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java @@ -48,7 +48,7 @@ public class ServiceProvider private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, ServiceProvider.class); - // applicationContex it lazily initialized + // applicationContex is lazily initialized private static BeanFactory applicationContext = null; private static boolean buildingApplicationContext; @@ -85,7 +85,12 @@ public class ServiceProvider } buildingApplicationContext = true; applicationContext = new ClassPathXmlApplicationContext(new String[] - { "dssApplicationContext.xml" }, true); + { "dssApplicationContext.xml" }, true) + { + { + setDisplayName("Application Context from { dssApplicationContext.xml }"); + } + }; buildingApplicationContext = false; } } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DssScreeningApplicationContext.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DssScreeningApplicationContext.java index 4bed7de351c..2fdd09ce7d6 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DssScreeningApplicationContext.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DssScreeningApplicationContext.java @@ -31,7 +31,10 @@ public class DssScreeningApplicationContext private static final String DSS_RPC_SERVICE_JSON = "data-store-rpc-service-screening-json"; - private static ApplicationContext instance; + private static ApplicationContext instance = null; + + // applicationContex is lazily initialized + private static boolean buildingApplicationContext; public static StreamSupportingHttpInvokerServiceExporter getDssRpcService() { @@ -47,8 +50,27 @@ public class DssScreeningApplicationContext { if (instance == null) { - instance = new ClassPathXmlApplicationContext(new String[] - { "screening-dssApplicationContext.xml" }, true); + synchronized (DssScreeningApplicationContext.class) + { + if (instance == null) + { + if (buildingApplicationContext) + { + throw new IllegalStateException("Building application context. " + + "Application context hasn't been built completely. " + + "Beans should access other beans lazily."); + } + buildingApplicationContext = true; + instance = new ClassPathXmlApplicationContext(new String[] + { "screening-dssApplicationContext.xml" }, true) + { + { + setDisplayName("Application Context from { screening-dssApplicationContext.xml }"); + } + }; + buildingApplicationContext = false; + } + } } return instance; } -- GitLab