TOMCAT OutOfMemory 正解

【高速互连技术】合规性测试规范:物理层信号完整性与链路均衡验证系统设计 内容概要:本文档介绍了分析工具进行实践对照,并关注后续规范版本更新以确保符合最终发布标准。 立即下载

原文地址:http://wiki.apache.org/tomcat/OutOfMemory

 

 

How to Deal With Out Of Memory Errors

These errors are rather commonly seen during development phases, and even on production servers. These errors are even more annoying than others, because they do not show any stack trace. The reason for this is that a stack trace would not be of help for these errors. The code that fails with an Out Of Memory will be, in most cases, a "victim" of the problem, and not the problem itself.

Although it is very tempting to blame Tomcat on these errors, the fact is that many of them have their causes in "mistakes" in the webapps. These mistakes usually come from programming patterns and techniques perfectly legal and safe on standalone applications, but that are not correct in a managed environment like a servlet container (that is, Tomcat).

This page will maintain a list of those "well-known mistakes", so anyone experiencing these problems, or wanting to avoid them, could check their webapps and correct them.

 

The General Rule

The first thing to do is to set the basis for these patterns to be recognized. This way, the developer will be able to find even those mistakes that are not listed in this page, and why not, add them here :-)

An Out Of Memory can be thrown by several causes:

  • A servlet trying to load a several GBytes file into memory will surely kill the server. These kind of errors must be considered a simple bug in our program.
  • To compensate for the data your servlet tries to load, you increase the heap size so that there is no room to create the stack size for the threads that need to be created. The memory required by each thread will vary by OS but can be as high as 2M by default and in some OS's (like Debian Sarge) is not reducible with the -Xss parameter. 1 Rule of Thumb, use no more than 1G for heap space in a 32-bit web application.

  • Deep recursive algorithms can also lead to Out Of Memory problems. In this case, the only fixes are increasing the thread stack size (-Xss), or refactoring the algorithms to reduce the depth, or the local data size per call.

  • A webapp that uses lots of libraries with many dependencies, or a server maintaining lots of webapps could exhauste the JVM PermGen space. This space is where the VM stores the classes and methods data. In those cases, the fix is to increase this size. The Sun VM has the flag -XX:MaxPermSize that allows to set its size (the default value is 64M)

  • Hard references to classes can prevent the garbage collector from reclaiming the memory allocated for them when a ClassLoader is discarded. This will occur on JSP recompilations, and webapps reloads. If these operations are common in a webapp having these kinds of problems, it will be a matter of time, until the PermGen space gets full and an Out Of Memory is thrown.

This last case is the one we intend to address here. It is directly related to the fact that the webapp is running on a managed environment, in which code changes can be commited without the application being stopped at all.

Once said this, the patterns to be included here will be those that, although being safe and legal on a standalone application, need to be refactored to make them "compatible" with the servlet container.

 

Threads

Any threads a web application starts, a web application should stop. ServletContextListener is your friend. Note Tomcat 7 will warn you if you do this and will also provide a (highly dangerous - use at your own risk) option to terminate the threads.

 

DriverManager

If you load a java.sql.Driver in your own classloader (or servlets), the driver should be removed before undeploying. Each driver is registered in DriverManager which is loaded in system classloader and references the local driver. Note Tomcat will do this for you if you forget.

 

                Enumeration<Driver> drivers = DriverManager.getDrivers();
                ArrayList<Driver> driversToUnload=new ArrayList<Driver>();
                while (drivers.hasMoreElements()) {
                        Driver driver = drivers.nextElement();
                        if (driver.getClass().getClassLoader().equals(getClass().getClassLoader())) {
                                driversToUnload.add(driver);
                        }
                }
                for (Driver driver : driversToUnload) {
                    DriverManager.deregisterDriver(driver);
                }

 

ThreadLocal

The lifecycle of a ThreadLocal should match that of a request. There is no guarantee that a thread will ever be used to process a request again so if a ThreadLocal is left on the thread at the end of the request there may be no opportunity for the web application to clean it up. Note Tomcat 7 will do this for you.

 

ContextClassLoader

There are various parts of the Java API that retain a permanent reference to the context class loader. If this happens to be a web application class loader then a memory leak will occur. Tomcat provides workarounds for these where known but there are undoubtedly others.

 

Logging Frameworks

Most logging frameworks provide a mechanism to release all resources when you have finished with the framework. These should always be used in a container environment.

 

When all else fails

If you still have a leak then you'll need to debug the root cause. The outline of the process is:

  1. You'll need a profiler (I use YourKit), Tomcat and a copy of the app that leaks.

  2. Configure Tomcat for use with the profiler. This usually means setting / adding to PATH and CATALINA_OPTS in setenv.(bat|sh)
  3. Start Tomcat with the app deployed.
  4. Reload the app once.
  5. Start up the profiler and connected it to Tomcat.
  6. Get a heap dump.
  7. Look for instances of WebappClassLoader. If there are more instances than you have apps deployed, you have a leak.

  8. If there is a leak, there should be one extra instance of WebappClassLoader.

  9. Examine each of the WebappClassLoader objects in turn to find the one where started==false.

  10. Trace the GC roots of this object to find out what is holding on to a reference to that object that shouldn't be. That will be the source of the leak.
frontend-design skills 立即下载

相关推荐

政府科技管理者在推动区域科技成果转化过程中,如何解决成果供需匹配效率低的问题?.docx

政府科技管理者在推动区域科技成果转化过程中,如何解决成果供需匹配效率低的问题?

[Place 30-99] Placer failed with error: ‘There are more instances than sites for type STARTUP‘解决方案

在工程中遇到的问题 百度查了很多方法,大致是说,在实例化多个模块的时候顶层没有输出,但是工程里面有输出,修改之后仍然存在问题。上Xilinx官网查询。Xilinx Customer Community如下 大致是把这个原语放到多个例化的模块的外面去。 解决过程 本来是这个原语在emif接口模块。 STARTUPE2 STARTUPE2_inst ( .CFGMCLK(CFGMCLK), // 1-bit output: Configuration internal osci

Alefssio的博客 6920

用于计算系统状态的卡尔曼最优增益和最小均方误差(MMSE)估计研究(Matlab代码实现)

内容概要:本文围绕用于计算系统状态的卡尔曼最优增益和最小均方误差(MMSE)估计展开研究,深入探讨了卡尔曼滤波在动态系统状态估计中的核心作用。文章系统阐述了卡尔曼滤波的数学基础,包括状态空间模型的建立、先验与后验状态估计、协方差矩阵的递推更新,以及最优增益矩阵的推导过程,确保在高斯白噪声环境下实现对系统状态的最小均方误差估计。结合Matlab代码实现,完整展示了算法从理论建模到仿真实验的全流程,涵盖系统建模、噪声设置、滤波迭代、状态更新与误差分析等环节,并通过仿真实验验证了算法在噪声干扰下对系统真实状态的高精度跟踪能力。该研究为控制工程、导航系统、信号处理及自动化领域中的状态估计问题提供了坚实的理论依据与高效的数值实现方案。; 适合人群:具备一定控制理论、概率统计基础和Matlab编程能力,从事自动化、电子信息、航空航天、机器人、导航定位等相关领域的科研人员、工程技术人员及高校研究生。; 使用场景及目标:①掌握卡尔曼滤波的基本原理及其在状态估计中的数学推导过程;②学习如何利用Matlab实现卡尔曼滤波算法并进行系统仿真与性能评估;③应用于目标跟踪、传感器融合、惯性导航、故障诊断、时间序列预测等实际工程中的动态状态估计问题。; 阅读建议:建议读者结合文中提供的Matlab代码进行动手实践,通过调整系统模型参数、过程噪声与观测噪声强度,观察滤波效果的变化,深入理解卡尔曼增益的自适应调节机制与MMSE估计的收敛特性。同时可进一步拓展学习扩展卡尔曼滤波(EKF)、无迹卡尔曼滤波(UKF)等非线性滤波方法,以应对更复杂的非线性系统状态估计挑战。

vivado中XADC和DDR3一起调用

vivado中同时调用XADC核和DDR3核时,会报错如下: 【place 30-99】 placer failed with error , there are more instances than sites for type XADC. 解决办法:将DDR3核中xadc部分设置为disable

sinat_39317726的博客 5775

高校技术转移办公室人员如何提升成果转化服务效率?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

国央企创新负责人如何利用平台实现技术需求的精准挖掘与匹配?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

Vivado FPGA调试报错记录

有多个DDR IP核时,Enable一个输出温度,其他Disable输入温度。例化了多个XADC,但XADC硬件资源没有那么多。

Blaze_Xu的博客 1100

自适应多机器人编队规划,以包围和跟踪具有运动和可见性约束的目标(Matlab代码实现)

内容概要:本文提出了一种自适应多机器人编队规划方法,旨在实现对具有运动能力和可见性约束目标的高效包围与持续跟踪,采用Matlab进行算法实现与仿真验证。该方法综合考虑了多机器人系统在动态环境中的协同控制、编队形态生成与保持、障碍物规避以及目标可见性维护等关键问题,通过设计分布式控制律使编队能够根据目标行为和环境变化自适应调整队形与运动轨迹,确保稳定包围并最大化目标观测质量。文中详细阐述了系统的数学建模过程、控制策略设计原理及约束处理机制,并提供了多场景下的仿真实验结果,验证了所提方法在复杂条件下的鲁棒性、灵活性与有效性。; 适合人群:具备自动化、机器人学、控制理论或人工智能等相关领域基础知识的科研人员及研究生,熟悉Matlab编程环境并致力于多智能体系统、协同控制、路径规划或智能无人系统研究的专业人士。; 使用场景及目标:①应用于多机器人系统在监视、围捕、搜救等任务中对移动目标的协同包围与跟踪控制;②为研究分布式编队控制、可见性优化、动态避障与多智能体协同决策等核心技术提供可复现的算法实例与理论支撑; 阅读建议:建议读者结合提供的Matlab代码逐模块分析算法实现细节,重点关注控制律设计、约束建模与仿真结果对比部分,宜在仿真环境中调整参数配置以深入理解系统性能边界与优化潜力。

Tomcat 内存溢出 "OutOfMemoryError" 问题总结 (JVM参数说明)

问题说明:公司内网环境中部署的jenkins代码发版平台突然不能访问了,查看tomcat的catalina.out日志发现报错如下: [root@redmine logs]# tail -f /srv/apache-tomcat-7.0.67/logs/catalina.out ...... Exception in thread "http-bio-8080-exec-...

weixin_30305735的博客 1086

2025.06.20【pacbio】|PB甲基化分析结果的统计与可视化介绍

本文介绍了PacBio甲基化数据的统计分析与可视化方法。主要内容包括:1) 分析甲基化位点分布、比例及染色体分布;2) 修饰基序(Motif)的统计与热图展示;3) 全基因组和局部区域测序深度可视化;4) 使用IGV查看单个reads修饰情况。文章提供了R代码示例,涵盖柱状图、分布图、热图等多种可视化形式,并建议了差异甲基化分析等进阶方法,帮助科研人员深入挖掘甲基化数据。

2067

LLaVA-1.5:多模态视觉问答新突破

LLaVA-1.5在多模态视觉问答(VQA)任务中取得了显著进展,主要得益于视觉-语言连接器的优化和特定任务数据集的增加。通过将连接器升级为两层MLP,模型在处理视觉与语言关系时表现更佳。同时,引入如OKVQA、OCRVQA等数据集,增强了模型在复杂视觉推理任务中的能力。在11个基准测试中,LLaVA-1.5超越了现有方法,展示了其强大的多模态能力。此外,模型通过提升输入图像分辨率、扩展语言模型和改进多语言能力,进一步提升了性能。尽管在短格式回答任务中初期表现不佳,但通过调整提示格式和微调,其性能显著提升

weixin_57060548的博客 947

tomcat OutOfMemoryError出现的三种情况解决办法

Tomcat内存溢出的原因在生产环境中tomcat内存设置不好很容易出现内存溢出。造成内存原因是不一样的,当然处理方式也不一样。这里根据平时遇到的情况和相关资料进行一个总结。常见的一般会有下面三种情况:1.OutOfMemoryError: Java heap space2.OutOfMemoryError: PermGen space3.OutOfMemoryError: unable to c...

HBQandJAVA的博客 1万+

基于osgEarth的二维态势中时变对象的绘制方法

在态势系统中,卫星、飞机的轨迹、覆盖等的几何数据随时间改变,称之为时变对象。在以OSGEarth实现的二维态势中,如果利用OSGEarth的预定义线、面类型处理这种几何数据的动态改变,则导致效率极具降低。介绍了此问题并给出解决技巧。

eyepeak的博客 2090

tomcat out of memory解决方法

如果在项目中用到了spring和hibernate并且数据量比较大的情况下,系统有时会突然出现“Out Of Memory”内存溢出的问题!可以试试下面的解决方案,如果机器配置比较好还可以适当加大点配置!     在netbeans安装的tomcat下的bin目录的catalina.bat文件下找到这行: Java代码   echo Using CAT

sunshine 2379

别再只用跳层连接了!手把手教你用DASI和MDCR模块提升红外小目标检测精度

本文详细介绍了如何利用DASI和MDCR模块提升红外小目标检测精度。通过分析传统跳层连接的缺陷,提出维度感知的特征选择性融合(DASI)和多尺度感受野精炼器(MDCR)的创新方案,显著提升小目标检测性能。实验证明,该方法在多个场景下AP@0.5提升达15.4%,特别适用于安防监控和遥感图像分析。

weixin_28715081的博客 224

Apollo Planning2.0决策规划算法代码详细解析 (1):环境搭建

1、官方提供连接:git clone https://github.com/ApolloAuto/application-pnc.git。此外,也更新了dreamview对pnc的支持,使得调试更加方便。apollo开源团队近期更新了planning版本,对代码进行了一定程度上的重构。(2)进入docker,并编译整个工程:./apollo.sh build_dbg。下载项目环境后使用aem进行环境配置;2、有一定基础建议直接拉取最新代码,自己手动进行编译。(1)环境安装: ./dev_start.sh。

自动驾驶Player的博客 1842

关于tomcat服务器出现OutOfMemory的问题

关与在tomcat服务器下,出现OutOfMemory(内存溢出)的问题,网上大部分给出的解决方案是修改,tomcat的物理内存,但是有时候是不起作用的,下面给出一种解决方案能 够达到预期的结果,就是在eclipse中修改配置,按照以下步骤进行设置: 1.打开eclipse--&gt;window--&gt; Preferences--&gt;Java--&gt;点击Installed JRE...

cyberHerman的博客 2456

【异常】飞书OpenClaw机器人 HTTP 401: Invalid Authentication 报错排查与解决方案

HTTP 401 是HTTP协议标准定义的未授权(Unauthorized)状态码,核心含义为请求方身份认证无效,服务端拒绝执行本次请求。飞书开放平台服务端对自建机器人的全链路鉴权校验失败。无论是机器人接收飞书事件推送的上行请求,还是机器人主动调用飞书开放平台API的下行请求,只要身份凭证无效、鉴权逻辑校验不通过,飞书服务端就会返回该报错,并最终透传到飞书客户端会话窗口中。

奶爸的编程之路,也就一周冷个三天 3768

Tomcat与Jetty深度对比

Tomcat:规范完整、生态繁荣、运维成熟,是绝大多数 Java Web 项目的稳妥默认选择。Jetty:轻量、可嵌入、长连接友好、协议跟进快,是嵌入式与高并发连接场景的优选。我的部署形态是什么、我的连接模型是什么、我的团队最熟悉什么。想清楚这三点,答案通常就很清晰了。

流水账 379

内网渗透(二)之基础知识-工作组介绍

在一个大型单位里,可能有成百上千台计算机互相连接组成局域网,它们都会列在"网络"(网上邻居)内。如果不对这些计算机进行分组,网络的混乱程度是可想而知的 为了解决这一问题,产生了工作组( Work Group)这个概念。将不同的计算机按功能(或部 门)分别列入不同的工作组,例如技术部的计算机都列入"技术部"工作组、行政部的计算机都 列入"行政部"工作组。要想访问某个部门的资源,只要在"网络"里双击该部门的工作组名 就可以看到该部门的所有计算机了。相比不分组的情况,这样的情况有序得多(尤其对大型局域网来说)。

把自己活成一道光,因为你不知道,谁会借着你的光,走出了黑暗。请保持心中的善良,因为你不知道,谁会借着你的善良,走出了绝望。请保持你心中的信仰,因为你不知道,谁会借着你的信仰,走出了迷茫。请相信自己的力量,因为你不知道,谁会因为相信你,开始相信了自己.... 1220

科研绘图系列:R语言绘制宏基因组分析的可视化图形(network & barplot & heatmap)

科研绘图系列:R语言多图形组合(network & barplot & heatmap)

专注生信领域 648

Java Tomcat 搭建 Web 网站实操教程(初学者版)

本文带你从零完成一次完整的 Java Web 网站搭建:装好 Tomcat、在 IDEA 里关联服务器、创建并部署 Web 项目、用浏览器访问页面,最后再解决新手最常踩的两个坑——404 找不到页面和端口被占用。全程只做必要操作,每一步都能跟着点完。

cats_eat_fish_的博客 207

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Boot4升后war Tomcat依赖怎么换

Boot4 打 war 到外置 Tomcat 时,Gradle 须换 tomcat-runtime;Maven 按 How-To 仍可用旧 starter,嵌入式 jar 不必换。

Amax3747的博客 345

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Tomcat学习笔记

本文详细介绍了在RHEL 9系统上从零部署Tomcat集群的完整流程,包括JDK安装、Tomcat配置、systemd服务管理,并实现Nginx反向代理与Memcached会话共享。通过Nginx统一入口实现负载均衡,利用Memcached解决Session跨服务器共享问题,确保用户登录状态在多台Tomcat间保持一致,提升系统可用性与扩展性。

2401_84044881的博客 355

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

上一篇: 视觉感知的拓扑理解
下一篇: 信息技术的边际
巧乐之
博客等级 码龄18年 32粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值