简体   繁体   中英

Java Swing app hangs when run in normal mode but runs fine in debug mode

I am writing a basic Java application with a Swing front-end. Basically it loads some data from a Derby database via Apache Cayenne and then displays it in a JTable. I'm doing my development in Eclipse and I don't think it's important but I'm using Maven for dependencies.

Now this works fine when I run using Debug but it seems to hang the display thread when I use the Run button. I've done a thread dump and I'm not 100% certain but everything looks good. I used Java VisualVM and the threads look fine there as well.

Strangely it seems to work intermittently. It's pretty consistent though and easy to reproduce. If anyone has any ideas, I'm all out of them.

It shouldn't be an issue that you are using Maven or Eclipse for Swing apps. We do that all that time with no problems. You said you're not 100% that everything looks good with the threads, so a posting of your threads would be useful, particularly when your application is hung - it's possible you have a deadlock.

The fact that you say it happens intermittently leads me to believe it's a threading problem. The debugger running may cause the threads to run differently, which is why it might work in debug mode. Swing threading issues are frequently caused by not performing GUI updates on the event dispatch thread since Swing is not threadsafe. Any operation that updates a swing component directly or indirectly (meaning if it updates the table model, which then updates the table) must be done on the event dispatch thread

If you can narrow down the block of code that is being invoked when the application freezes, you should post that if you can, and that would be helpful as well.

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