memory-leaksnetflixnetflix-archaius

Memory Leak Issue with spring-cloud-starter-hystrix and spring-cloud-starter-archaius integration


We are using spring-cloud-starter-hystrix with spring-cloud-starter-archaius where we are unable to stop the poolingconfigurationSource thread of archaius once the war is un-deployed. But spring-cloud-starter-archaius is working fine without hystrix and thread is stopped once war is un-deployed.


Solution

  • **Issue resolved permanently.**
    
    **There are 2 approach :**
    1) Create ContextListener in Servlet and in destroy method , copy below code.
    
    2) If you are using Histrix + Spring Boot + Archaius then on main spring application java file , copy below code in method annonated with @PreDestory annotations.
    
        **Solution :**
    
        try {
        if (ConfigurationManager.getConfigInstance() instanceof DynamicConfiguration) {
        DynamicConfiguration config = (DynamicConfiguration) ConfigurationManager.getConfigInstance();
        config.stopLoading();
        } else if (ConfigurationManager.getConfigInstance() instanceof ConcurrentCompositeConfiguration) {
        ConcurrentCompositeConfiguration configInst = (ConcurrentCompositeConfiguration) ConfigurationManager
        .getConfigInstance();
        List<AbstractConfiguration> configs = configInst.getConfigurations();
        if (configs != null) {
        for (AbstractConfiguration config : configs) {
        if (config instanceof DynamicConfiguration) {
        ((DynamicConfiguration) config).stopLoading();
        break;
        }
        }
        }
        }
        } catch (Exception e) {
        e.printStackTrace();
        }