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.

- 3,383
- 7
- 31
- 78
-
Maybe this helps you: [Lesson: Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) – pzaenger Jul 23 '16 at 10:36
-
Thank you I will take a look at it :) – SlimenTN Jul 23 '16 at 10:38
2 Answers
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.

- 1
- 1

- 116
- 3
-
Nice tip thank you especially the "jstack" I need something like that :) – SlimenTN Jul 23 '16 at 10:46
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;
});

- 618
- 5
- 17
-
-
And yes u're right I have some large tasks inside some actionListeners. – SlimenTN Jul 30 '16 at 09:21
-
I've updated it with an example. A flag would just be a static boolean that you check in the main loop. Hope this helps :) – Drgabble Jul 31 '16 at 12:11
-