Tomcat 8.5 Wildfly 15 Java 8 OutOfMemoryError和启动速度非常慢 [英] Tomcat 8.5 Wildfly 15 Java 8 OutOfMemoryError and very slow startup

查看:145
本文介绍了Tomcat 8.5 Wildfly 15 Java 8 OutOfMemoryError和启动速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启用Spring 4的Maven项目中启用@Autowrid后,启动应用程序将OutOfMemoryError设置为大约800 ManegedBeans Spring,900 Services,1000 @Component和1000 @Repository. 我在Tomcat和Wildfly中增加了参数-Xms1024m -Xmx4g,在应用程序中,在applicationContext.xml中添加了default-lazy-init = "false"参数,并且启动该应用程序的成本很高.我想知道删除

After enabling @Autowrid, Maven project with Spring 4, in approximately: 800 ManegedBeans Spring, 900 Services, 1000 @Component and 1000 @Repository, the startup application trhow an OutOfMemoryError. I increased the parameters -Xms1024m -Xmx4g in Tomcat and Wildfly, in the application I added the default-lazy-init = "false" parameter in applicationContext.xml and at a great cost the application is starting. I would like to know if there is any advantage in removing

@Autowired 
private AnyService anyService;

在所有类中使用

public void execute() {
   AnyService anyService = (AnyService)applicationContext.getBean(AnyService.class);
   anyService.execute();
}

方法中的

. 使用局部变量而不是实例可以优化启动吗?给GC带来一些好处?调用applicationContext.getBean(AnyService.class)可能会恶化方法的性能吗?

within the methods. Does using the local variable instead of the instance can optimize the startup? Brings some benefit to the GC? The call applicationContext.getBean(AnyService.class) may worsen performance of methods?

推荐答案

OutOfMemoryError和启动缓慢是两个不同的问题.我认为您不必删除@Autowired注释.

OutOfMemoryError and slow startup are two different question. I think you don't have to remove your @Autowired annotation.

首先,您应该确定导致加载缓慢的bean(例如db连接),并在该类中添加@Lazy,您可以参考本文确保特定的Bean首先被初始化

First you should identify which bean cause slow loading (for example db connection), and add @Lazy at that class , you can reference this article spring-lazy-annotation-use-cases. and some bean should load first Make sure a particular bean gets initialized first

第二,使用Spring XML配置而不是组件扫描或限制组件扫描范围可能会有所帮助.确保仅使用应用程序的最低限度要求的组件

Second, use Spring XML configuration instead of component scan or limit component scan scope may help. Make sure only uses the minimally required components of your app

这篇关于Tomcat 8.5 Wildfly 15 Java 8 OutOfMemoryError和启动速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆