1

I have a Swing GUI running on WinXP.

Sometimes, when i do something else (surf on the web...) and then i want to go back to my program, the GUI appears but is totally frozen, i can't do anything on it.

I have to wait (it can be 10sec or 5min) untill it works again.

I noticed the same problem when i come back from the screensaver (so I disabled it).

The machine isn't in cause, RAM and processor levels are ok.

Do you have any idea of the source of this very annoying problem? Maybe a repaint problem?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
caRameL
  • 633
  • 6
  • 15
  • 3
    Possibly threading problems - do you run any calculations in the GUI threads that might take time and freeze the GUI when your applciation gets the focus back? – assylias Sep 20 '12 at 13:14
  • +1 to comment, if Swing draw thread is frozen then something is using that thread to do things that it shouldn't – Jack Sep 20 '12 at 13:16
  • Your application could be working, and doing a lot of work... It just isn't GUI based so it appears to be slow / lagging. As others have said threads may be the way to go to offload some of the donkey work. However, without any code at all it is hard to judge... – RossC Sep 20 '12 at 13:24
  • I have separated threads that do some operations at regulars intervals. Apart from that, actions are only set with listeners. I never specified my application to run some code when it regains focus. – caRameL Sep 20 '12 at 13:27
  • 3
    The next time you encounter that, take a thread dump (or multiple ones) so that you at least know what the application is doing (and more in particular what the EDT is doing). For example `jstack` allows to take a thread dump – Robin Sep 20 '12 at 13:27
  • @caRameL for better help sooner post an SSCCE denostrated issue with freeze, otherwise this qeustion isn't answerable in this form – mKorbel Sep 20 '12 at 13:27
  • It might be a pointless question, but does it happen on every computer you've tried it on, or just yours? It's nearly impossible to judge since we don't know anything about your code... – RossC Sep 20 '12 at 13:57
  • That's the problem, it happens on every computer except mine (same model than my clients ones) so it's very hard to debug. – caRameL Sep 20 '12 at 14:20

1 Answers1

2

There might be many explanations to that:

  1. Your app does some heavy operations in EDT thread (thread that controls interface updates)
  2. There might be a UI update problems caused by errors in L&F or components (a rare case)
  3. GC happens due to some internal call and handles the whole application (less likely)
  4. Some native or old JDK problems with app windows (almost 0% chance that it is your case)

Usually the 1st explanation works and in that case you should just review your code and extract all "heavy" operations in a separate threads.

Anyways, i can't say anything more specific without seeing the code...

Mikle Garin
  • 10,083
  • 37
  • 59
  • Actually, it happens when i came back from others screen and the time it needs to work again usually depends on time i wasn't focused on my program. GC doesn't work if i'm not focused on my application? – caRameL Sep 20 '12 at 13:37
  • 1
    GC works when it is needed to work (for e.g. memory reached its limit) or when it is directly called through System.gc(). It was just a guess anyway. You have to find out what exactly starting to run when your application get the focus (you can do it by profiling or debugging your application) - otherwise there is no way to help you with the questions. Less likely that it is Java problem. – Mikle Garin Sep 20 '12 at 13:43
  • 1
    Also look for [empty exception handlers](http://stackoverflow.com/q/12487583/230513) and [*Initial Threads*](http://download.oracle.com/javase/tutorial/uiswing/concurrency/initial.html) violations. – trashgod Sep 20 '12 at 15:27