简体   繁体   English

JAVA桌面应用程序挂起时该怎么办?

[英]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. 以下是我已完成的步骤。

  1. Use log4j to log all exception messages. 使用log4j记录所有异常消息。 (As I think it may cause from Network connection, data base connection etc..) (我认为这可能是由于网络连接,数据库连接等引起的。)

  2. 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 我已经尝试并测试了可能发生异常的每种情况,例如

  1. Network connection down. 网络连接断开。
  2. Connection timeout. 连接超时。
  3. Enterprise sending message back as 500 Internal error.(and all http errors) 企业发回的邮件为500内部错误(以及所有HTTP错误)。
  4. Invalid XML format of SOAP message. SOAP消息的XML格式无效。
  5. Fail while parsing XML to 将XML解析为时失败
  6. Connection to database can not establish. 无法建立与数据库的连接。
  7. Invalid SQL Statement. 无效的SQL语句。
  8. Invalid data type of field in data base. 数据库中字段的数据类型无效。

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.

相关问题 Java Web应用程序作为桌面应用程序,我应该选择哪些框架? - Java web app as desktop app, which frameworks should I choose? Java核心转储时我该怎么办? - what should I do when Java core dumps? 我应该将什么样的Swing外观用于Java桌面应用程序? - What Swing look and feel should I use for a Java desktop application? Java-Spintax,我该怎么办? - Java - Spintax , what should i do? 如何将桌面Java应用程序连接到在线数据库(用于虚拟人)? - How do I connect a desktop java app to an online database (for dummies)? 当我在 Java 中读取 API 时,我在字符串中使用 ÃŽ 代替 Î。 我该怎么办? - When I am reading a API in java I get ÃŽ in place of Î in a string. What should I do? 选择Java条形码库时应考虑哪些具体标准,您推荐哪些标准? - What are the specific criteria I should consider when choosing a Java Barcoding Library and which ones do you recommend? 如何获得对Javafx Spring Boot桌面应用程序的OAuth2访问令牌? - What should I do to get an OAuth2 access token to my javafx spring boot desktop application? Java调试时会导致我的进程挂起的原因 - When Java debugging what could cause my process to hang 为什么我的Java客户端/服务器应用程序在使用ObjectInputStream时挂起但在我使用带有InputStreamReader的BufferedReader时却没有? - Why does my Java client/server app hang when using ObjectInputStream but doesn't when I use BufferedReader with InputStreamReader?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM