4

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

4

3 回答 3

2

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

@EnableCircuitBreaker
@SpringBootApplication
public class Application {

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

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

}
于 2018-03-06T08:36:35.547 回答
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();
    } 
于 2018-03-07T11:56:32.130 回答
0

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

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

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

于 2018-05-21T19:31:57.097 回答