【问题标题】:Memory Leak Issue with spring-cloud-starter-hystrix and spring-cloud-starter-archaius integrationspring-cloud-starter-hystrix 和 spring-cloud-starter-archaius 集成的内存泄漏问题
【发布时间】:2018-08-14 00:43:26
【问题描述】:

我们将 spring-cloud-starter-hystrix 与 spring-cloud-starter-archaius 一起使用,一旦取消部署战争,我们将无法停止 archaius 的 poolingconfigurationSource 线程。但是 spring-cloud-starter-archaius 在没有 hystrix 的情况下工作正常,并且一旦取消部署战争,线程就会停止。

【问题讨论】:

  • "pollingConfigurationSource" 线程不会在应用程序从应用程序服务器取消部署时自动终止。该线程由archaius API 创建。在启动应用程序和取消部署应用程序后检查了 visualVM 中的线程转储。在取消部署时,相同的线程会被自动终止,然后立即创建具有相同名称的新线程(pollingConfigurationSource)。

标签: memory-leaks netflix netflix-archaius


【解决方案1】:

尝试在 Spring 应用程序关闭之前重置 Hystrix

@EnableCircuitBreaker
@SpringBootApplication
public class Application {

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  @PreDestroy
  public void cleanUp() {
    Hystrix.reset();
  }

}

【讨论】:

  • 感谢 Davin 的及时回复。
  • 我尝试过同样的方法,但它不起作用。从服务器取消部署应用程序后,它会再次自动创建新线程。请参阅下面的线程转储以获取信息。
  • 线程转储:“pollingConfigurationSource”#227 守护进程 prio=5 os_prio=0 tid=0x000000001cafd800 nid=0x218 等待条件 [0x000000002dd0f000] java.lang.Thread.State: TIMED_WAITING (parking) at sun。 misc.Unsafe.park(本机方法)
  • 你应该能够从你的项目中删除 spring-cloud-starter-archaius,因为 Archaius 是 Hystrix 的传递依赖。上面提出的解决方案是否可以在没有额外依赖的情况下工作?
  • @Davin 这对我不起作用。当我运行项目时,它会给我日志:Process finished with exit code 1
【解决方案2】:
**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();
    } 

【讨论】:

    【解决方案3】:

    Davin 和 Ashish Patel 都是对的:Spring cloud 导致了多个泄漏。

    Davin 提出的解决方案可以部分修复名为pollingConfigurationSource 的一些线程的存在。您还需要确保在您的类路径中没有任何名为config.properties 的文件,因为com.netflix.config.sources.URLConfigurationSource(查看所有案例的源代码)将搜索公共补丁并启动一个执行程序线程。代码中有多个路径导致线程“pollingConfigurationSource”上的 executorservice 启动(并不总是停止)。在我的情况下,删除“config.properties”解决了这个泄漏

    我知道的另一个泄漏是由 Hystrix/RjJava 引起的。而不是调用Histrix.reset 调用rx.schedulers.Schedulers.shutdown(); 这将强制线程“RxIoScheduler-”退出。

    【讨论】:

      猜你喜欢
      • 2019-04-29
      • 1970-01-01
      • 2022-07-14
      • 2021-04-02
      • 2017-08-28
      • 2021-05-07
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多