[英]What should I do when JAVA desktop app hang on?
My java desktop application (develop with netbean) is hanging on while running for long time (around 10 hours). 我的Java桌面应用程序(使用netbean开发)在长时间(约10个小时)运行时仍处于挂起状态。
Purpose of my application is to call SOAP web service to enterprise system. 我的应用程序的目的是将SOAP Web服务调用到企业系统。 So, It always takes long time for execution.
因此,执行总是需要很长时间。
But in the first 1 - 4 hours it works very well. 但是在最初的1-4个小时中,效果很好。
this problem always come when running more than 10 hours. 运行10个小时以上时,总是会出现此问题。
There are steps that I have done below. 以下是我已完成的步骤。
Use log4j to log all exception messages. 使用log4j记录所有异常消息。 (As I think it may cause from Network connection, data base connection etc..)
(我认为这可能是由于网络连接,数据库连接等引起的。)
Call System.gc() every time in looping statement (AS I think when it runs for long time. It doesn't release resource back to system so I force it to call garbage collector). 每次在循环语句中调用System.gc()(因为我认为它长时间运行。它不会将资源释放回系统,因此我强制它调用垃圾收集器)。
I have tried and tested in every situation that exception may happens such as 我已经尝试并测试了可能发生异常的每种情况,例如
Every exceptions will be captured by log4j and be able to continue running. 每个异常都将由log4j捕获并能够继续运行。
But that's work well in the first 1 - 4 hours. 但这在最初的1-4个小时中效果很好。 When it reach to 10 hours.
当达到10小时。 It is hanged on.
它挂了。 No log.
没有日志。 No message.
没有讯息
I use JAVA JDK 1.8, MySQL data base 5.5.4, Window server 2008 R2 64bits 我使用JAVA JDK 1.8,MySQL数据库5.5.4,Window Server 2008 R2 64位
Could you please help suggest what spot or point I am missing? 您能帮我建议我遗漏的点或点吗?
Anything else should I concern and check? 我还有其他需要检查的地方吗?
Best Regards, 最好的祝福,
The simple answer: DEBUG, add lots of logging/debugging. 简单的答案:调试,添加许多日志记录/调试。
You are using only using log4j to check for errors, but your application is obviously hanging elsewhere before log4j has a chance to make a log, so instead I suggest you do one of two things: 您仅使用log4j来检查错误,但是您的应用程序显然在log4j有机会记录日志之前挂在其他地方,所以我建议您执行以下两项操作之一:
1) Create a new thread that checks the state of your application (You will obviously need to expose parts of your code to that thread and check it on a periodic basis). 1)创建一个新线程来检查应用程序的状态(显然,您需要将部分代码暴露给该线程并定期检查它)。
2) The easier option would be to add lots of debug code to log everything to file, then when your application hangs it will be really easy to see what the last action was by checking the log file, and possibly know exactly what caused the issue. 2)比较容易的选择是添加大量调试代码以将所有内容记录到文件中,然后在应用程序挂起时,通过检查日志文件来查看上一个操作的确很容易,并且可能确切地知道是什么导致了问题。 So personally rather that just logging errors I would make a log before processing any of the following: incoming connection, timeout, call to database, http errors, and pretty much any other major event, and i would also make a log after all of the following have been processed.
因此,就个人而言,而不是仅记录错误,我将在处理以下任何一项之前记录日志:传入连接,超时,对数据库的调用,http错误以及几乎所有其他重大事件,并且在所有以下已处理。 That way when your application hangs just look for whatever process has not been completed and then you can start investigating why that happened by adding even more debug/logging.
这样,当您的应用程序挂起时,只需查找尚未完成的任何过程,然后就可以通过添加更多的调试/日志记录开始调查原因。
Don`t forget to refine or remove all your debug code once you solve the problem else you may suffer some performance loss unless you do it all in a different thread. 解决问题后,请不要忘记细化或删除所有调试代码,否则可能会损失一些性能,除非您在不同的线程中进行所有操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.