简体   繁体   中英

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).

Purpose of my application is to call SOAP web service to enterprise system. So, It always takes long time for execution.

But in the first 1 - 4 hours it works very well.

this problem always come when running more than 10 hours.

There are steps that I have done below.

  1. Use log4j to log all exception messages. (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).

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)
  4. Invalid XML format of SOAP message.
  5. Fail while parsing XML to
  6. Connection to database can not establish.
  7. Invalid SQL Statement.
  8. Invalid data type of field in data base.

Every exceptions will be captured by log4j and be able to continue running.

But that's work well in the first 1 - 4 hours. When it reach to 10 hours. 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

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:

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).

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM