首页 > 解决方案 > java process finishes after some time with no particular reason

问题描述

I have a java .jar file that i launch on an AWS instance in detached mode. So when i exit the ssh session, it still runs.

The app does some network stuff, and is expected to run for days until it finishes it task.

I have made logs all over the app, made log in the end of main method. I also made a global try/catch and added logging to the catch section.

Still, after some days i enter into ssh and see that the app just stopped running. No exceptions, main method did not complete because the log in the end did not trigger. It seems that the process was just killed in the middle of working. Sometimes it works for 5 hours, sometimes for 3-4 days without stopping.

I have no idea what could be the cause of this. I expect the java process to run until it finished, or until it crashes. Am i missing something?

upd: it is an aws t2.micro, i think, the free tier one. It runs ubuntu 18.04.3 LTS

标签: javaamazon-web-serviceskotlin

解决方案


您需要监视服务器和应用程序。首先要查看的是任何 CPU 或内存峰值的实例 cloudwatch 统计信息。如果你找到了,你就知道如果你想在微实例上运行你的应用程序需要修复什么。进一步阅读

使用 CloudWatch 监控您的实例

或者,您可以在运行应用程序时定期收集和转储 Java 进程统计信息。这可以深入了解堆、堆栈和 cpu 的使用情况。检查此 SO 帖子以获取更多详细信息:

如何在 Java 中监控计算机的 CPU、内存和磁盘使用情况?


推荐阅读