diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index e62a95f..79952b6 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -64,6 +64,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem // ckan utils methods private CKanUtilsImpl instance; + private Object LOCK = new Object(); /** * Since it needs the scope, we need to check if it is null or not @@ -72,13 +73,17 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem private CKanUtilsImpl getCkanUtilsObj(){ if(instance == null){ - // retrieve ckan information - try{ - String currentScope = ScopeProvider.instance.get(); - logger.debug("Scope is " + currentScope); - instance = new CKanUtilsImpl(currentScope); - }catch(Exception e){ - logger.error("Unable to retrieve ckan information", e); + synchronized(LOCK){ + if(instance == null){ + // retrieve ckan information + try{ + String currentScope = ScopeProvider.instance.get(); + logger.debug("Scope is " + currentScope); + instance = new CKanUtilsImpl(currentScope); + }catch(Exception e){ + logger.error("Unable to retrieve ckan information", e); + } + } } }