tags:

views:

115

answers:

1

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.

+3  A: 

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.

Jeff Storey
+1 for event dispatch thread. I'd also advise switching the default look-and-feel to Substance (https://substance.dev.java.net/) which *enforces* Swing-related stuff to be done in the EDT or the app fails. This has been useful to me for debugging.
Chris Dennett
Sweet - I was aware of different ways to check for EDT violations, but didn't know that there was a look and feel that would do that.
Joshua McKinnon
Jeff Storey
Of course, but still handy as an easy way to detect problems when developing.
Joshua McKinnon