2

I have developed an advanced java application (Financial Management) for desktop using swing and I have some clients who are using it. Recently one of my clients said that some times the application freezes and he had to restart it when he does a lot of work on it.

The problem is when I test the application on my machine works fine and don't freeze even when I overload it with some actions and data !

Can anyone give me some tips about what's the possible things that can makes a swing java application does such things and how can I improve the performance of my application.

SlimenTN
  • 3,383
  • 7
  • 31
  • 78

2 Answers2

3

It can have a lot of causes. My first guess would be a race condition somewhere in your code. An interesting fact to go further on is if the application uses 0% CPU time or 100% CPU time while it appears frozen. 0% Would indicate some things are waiting on each other (deadlock). 100% Would indicate an endless loop. If you can access the machine of the client you might be able to connect a debugger to the frozen application or create a dump of stacktraces using jstack.

Community
  • 1
  • 1
Ronald Klop
  • 116
  • 3
0

One possibility might be running large tasks inside the Swing thread instead of another thread, for example executing a large task inside an actionListener:

foo.addActionListener((ActionEvent ae) -> {
    // time consuming task
});

This would cause all the user interface parts to freeze until the function returns. Make sure that functions such as this pass on actual work to a new thread or set flags to perform work in existing threads.

For example have a static boolean in Main which is checked in the main loop:

public static class Main {
    public static boolean do_action;
    public static void main(){
        while( true ) {
            if( do_action ) {
                // do action of some kind
                do_action = false;
            }
            // sleep or do other things
        }
    }
}

And an action listener like so:

foo.addActionListener((ActionEvent ae) -> {
    Main.do_action = true;
});
Drgabble
  • 618
  • 5
  • 17