博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
"Cannot allocate memory" OutofMemory when call Ant to build Polish project in Tomcat
阅读量:4136 次
发布时间:2019-05-25

本文共 2726 字,大约阅读时间需要 9 分钟。

I have written one J2EE web service which was run in Tomcat, this service will call Ant to build one J2ME Polish project. It can be run without problem, aber will got such exception "ProGuard is unable to obfuscate: java.io.IOException: Cannot run

program "java": java.io.IOException: error=12, Cannot allocate memory" after several times' building. This is abvious OutofMemory exception.

Tomcat service was run on CentOS linux, the first thing what i thought is to increase the initial memory of Tomcat.

Edit the catalina config file:

opt/tomcat/bin/catalina.sh (catalina.bat for win)
add such command line:
CATALINA_OPTS="-Xms512m -Xmx512m -XX:MaxPermSize=512m" 
(I have also tried this: JAVA_OPTS="$JAVA_OPTS -Xms512M -Xmx512m" , but Tomcat can not be started.)
Anyway, Tomcat now has enough memory.

Continue the testing. Now situation is better, after more than 50 times' building, Ant still threw this exception. Restarted Tomcat can not help solving this problem, memory of Tomcat will increase after each building till this exception occused. Ok, i tried to optimize my code, release every object when finished their life, this only help a little bit. This exception always occured.

No idea now, google............found one article:  and this information:

"If you are compiling with javac task in Apache Ant, set fork attribute
to true, to run javac in a separate process with its own heap size
settings. If fork is set to false, or not set (default is false), javac
will run in the same process as Ant, which has a default maximum heap
size of 64m."

<javac srcdir="${basedir}/src"

destdir="${basedir}/build/classes"
classpath="${project.classpath}"
fork="true"
memoryinitialsize="256m"
memorymaximumsize="256m">
</javac>

This <javac> section will be set under <target>. 64m for Tomcat service is not tiny thing.

Useful information, Ant can be alocated with seperate memory and thread. But J2ME Polish build can not use <javac> element, but it support <compiler> element, which "calls the Java compiler normally with the appropriate classpath as well as bootclasspath for the

current target device. In some cases you might want to adjust the compiler settings, however, so you can use the
nested <compiler> element. Along to all attributes of the standard <javac> task......."

Great! So I add this element under :

<target>
-<j2mepolish>
--<build> 
---<compiler fork="yes" memoryinitialsize="128m" memorymaximumsize="128m"/>

and test Tomcat again, after Ant building task, memory of Tomcat increase only a little bit, it is normal, the Ant has used seperated memory for building the Polish task! Tomcat can stay stable now.

With this <compiler> element, we can use other optional arguments such as classpath, sourcepath....

转载地址:http://qkqvi.baihongyu.com/

你可能感兴趣的文章
OpenFeign学习(四):OpenFeign的方法同步请求执行
查看>>
OpenFeign学习(六):OpenFign进行表单提交参数或传输文件
查看>>
Ribbon 学习(二):Spring Cloud Ribbon 加载配置原理
查看>>
Ribbon 学习(三):RestTemplate 请求负载流程解析
查看>>
深入理解HashMap
查看>>
XML生成(一):DOM生成XML
查看>>
XML生成(三):JDOM生成
查看>>
Ubuntu Could not open lock file /var/lib/dpkg/lock - open (13:Permission denied)
查看>>
collect2: ld returned 1 exit status
查看>>
C#入门
查看>>
C#中ColorDialog需点两次确定才会退出的问题
查看>>
数据库
查看>>
nginx反代 499 502 bad gateway 和timeout
查看>>
linux虚拟机安装tar.gz版jdk步骤详解
查看>>
python实现100以内自然数之和,偶数之和
查看>>
python数字逆序输出及多个print输出在同一行
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>