- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试设置一种方法来处理我的应用程序中的内存不足错误。到目前为止,我已将以下选项添加到我的 Gradle 构建文件中:
task appStartScripts(type: CreateStartScripts) {
def tplName = 'startTemplate.sh'
assert project.file(tplName).exists()
defaultJvmOpts = ["-XX:+HeapDumpOnOutOfMemoryError",
"-XX:HeapDumpPath=\$HOME/log/",
"-XX:OnOutOfMemoryError=./\$HOME/application/bin/restart.sh",
"-Xms64m", "-Xmx124m"]
dependsOn shadowJar
applicationName = 'start'
defaultJvmOpts += ["-Dspring.profiles.active=ENV_VARIABLE"]
classpath = startShadowScripts.classpath
mainClassName = startShadowScripts.mainClassName
outputDir = new File(project.buildDir, 'scriptsShadow')
doLast {
// IMPORTANT! needed to ensure HOME environment variable is expanded correctly
unixScript.text = unixScript.text.replace('\\$HOME', '\'"$HOME"\'')
unixScript.text = unixScript.text.replace('ENV_VARIABLE', '\'"$1"\'')
}
其中 XX:OnOutOfMemoryError 在发生内存不足错误时调用重启脚本。在 restart.sh 脚本本身中,我有以下内容:
while true : do
java -XX:+ExitOnOutOfMemoryError -jar application.jar
sleep 5
done
./start.sh
要杀死应用,等待5秒,然后调用同目录下的启动脚本重启应用。
为了对此进行测试,我在我的一个获取请求中添加了一个无限循环:
@GET
@Timed
@Path("/{ids}")
public List<Profile> getProfileByID(@PathParam("ids") String ids) {
boolean forever = true;
try {
logger.info("STARTED SERVICE: getProfileID with the following parameters: IDs = {}", ids);
int[] array = idsStringToArray(ids);
List<Profile> profileList = profileManager.getProfiles(array);
List<Integer> myList = new ArrayList<Integer>();
while (forever) {
profileManager.getProfiles(array);
myList.add(1000);
}
logger.info("COMPLETED SERVICE: getProfileID with the following parameters: Ids = {}", ids);
return profileList;
}
myList 将继续向其添加更多项目,消耗内存。
就是说,我还不能引发错误来触发脚本。还有什么我可以做的吗?
此外,这里是服务的 top 命令的结果:
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.4 us, 1.3 sy, 0.0 ni, 97.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 32160180 total, 21291040 free, 4559124 used, 6310016 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 27127132 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
30504 user1 20 0 3778748 371724 18048 S 4.0 1.2 3:50.33 java
编辑:我只是尝试在代码中直接调用 OOM 错误,但它只是抛出异常,没有别的:
@GET
@Timed
@Path("/{ids}")
public List<Profile> getProfileByID(@PathParam("ids") String ids) {
boolean forever = true;
try {
logger.info("STARTED SERVICE: getProfileID with the following parameters: IDs = {}", ids);
int[] array = idsStringToArray(ids);
List<Profile> profileList = profileManager.getProfiles(array);
throw new OutOfMemoryError();
}
最佳答案
我能够引发错误。我通过比以前更多地降低堆空间来做到这一点:
"-Xms64m", "-Xmx124m",
并通过让我的 get 方法生成一个 long 和 long 数组,l:
@GET
@Timed
@Path("/{ids}")
public List<Profile> getProfileByID(@PathParam("ids") String ids) {
boolean forever = true;
try {
logger.info("STARTED SERVICE: getProfileID with the following parameters: IDs = {}", ids);
int[] array = idsStringToArray(ids);
List<Profile> profileList = profileManager.getProfiles(array);
long[] l = new long[Integer.MAX_VALUE];
关于java - 如何在 OOM 时使用 -XX :OnOutOfMemoryError= 执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57330534/
我在一个不是很大的数据帧上使用 pyspark 中的广播连接,但出现了 oom 错误。代码非常简单,如下所示: from pyspark.sql.functions import broadcast
我正在使用 JDK 1.8.0_u66,-XX:+CrashOnOutOfMemoryError 选项尚不可用。所以我最终设置了 -XX:OnOutOfMemoryError="kill -9 %p"
我正在尝试监视上次在一台生产计算机上的进程(由于内存不足而崩溃)。该进程正在使用 -XX:OnOutOfMemoryError=jmap 选项运行。这是什么意思?这是否意味着它会在 OutOfMemo
我在尝试将 -XX:OnOutOfMemoryError="kill -9 %p" 命令传递到我的 jvm 参数时遇到问题。 我正在使用 Jetty7,并将其包含在 start.ini 文件中。启动时
我正在尝试设置一种方法来处理我的应用程序中的内存不足错误。到目前为止,我已将以下选项添加到我的 Gradle 构建文件中: task appStartScripts(type: CreateStart
我的目标是在抛出 java.lang.OutOfMemoryError 时执行脚本(Windows 批处理文件),按照 Hotspot VM Options 中描述的选项 -XX:OnOutOfMem
我在尝试将 -XX:OnOutOfMemoryError="kill -9 %p" 命令传递到我的 jvm 参数时遇到问题。 我正在使用 Jetty7,并且在 start.ini 文件中有这个。在启动
我有一个 Java 应用程序,我想在遇到 OutOfMemoryException 时运行脚本 这很好用: $ java -server -XX:OnOutOfMemoryError="./oom_s
我使用 -XX:OnOutOfMemoryError=\"kill -9 %p\"。它适用于大多数内存不足的情况,但不会终止 java.lang.OutOfMemoryError:无法创建新的 nat
我对 Windows 批处理编程完全陌生。我想要实现的是为 Java 应用程序编写启动脚本。然而,它并没有启动 Java 应用程序,而是打印出来 Usage: java [-options] clas
Java HotSpot VM Options中有以下两个选项: -XX:OnError=";" Run user-defined commands on fatal error. (Introduc
我正在尝试在 OOME 发生时重新启动进程。 Java 二进制文件使用两个 shell 脚本启动,其中一个导入另一个。我无法控制第一个,但可以根据需要修改第二个。这是我正在尝试做的原型(prototy
我是一名优秀的程序员,十分优秀!