Solved

Swing Performance

Posted on 2004-09-01
10
207 Views
Last Modified: 2013-12-29
I've been developing my swing application on my laptop (P4 HT 3.06 ghz  512MB) and it runs essentially seamlessly.  I have been developing it on this machine for some time now and had never given consideration to performance implications for running on a slower system.  The desktops at our company are P4 1.8ghz 256MB machines and the application runs absolutely horrendously...I mean to the point that the productivity loss to the person using it would make it not worthwhile to use.

Does anybody have any advice or maybe links to resources that I can check out so that I can attempt to streamline the code and perhaps make it more efficient?

Thanks,
David
0
Comment
Question by:lomidien
10 Comments
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11957971
My first suggestion: cut any nonessential stuff, right from the start. If left in debugs, etc. take them out.
Second: Try running Runtime.gc() occasionally to reclaim some memory. I know it should be running automatically, but just to be sure...
Third: The issue with Java/Swing is RAM. Usually the processor is not an issue (heck, I'm on a 667 :P ). Try to do things in smaller chunks and not have as many things happening at once. For instance, if you transfer files, transfer them 5 MB at a time, etc. This allows Java to free up memory between tasks.

I hope this helps a bit...
0
 
LVL 15

Accepted Solution

by:
Javatm earned 500 total points
ID: 11957989
Does anybody have any advice or maybe links to resources that I can check out so that I can attempt to streamline the code and perhaps make it more efficient?

1. 1st thing that you need to remember is to close all open streams.
2. You can finalize any objects that you want to be suggested in GC.
3. Still not resolve ? use a java profiler to monitor the efficiency of
    your java program. A profiler detects any problem in your codes.

Here is a link that will help you in the performance of your application :
http://www.javaperformancetuning.com/resources.shtml

If you want a java profiler here are the best :

Java Profiler - JProfiler :
http://www.ej-technologies.com/ products/jprofiler/overview.html

Extensible Java Profiler :
http://ejp.sourceforge.net

Notes : JProfiler is free to use for a month I think then you need to purchase
it unless you request for another trail.

Hope that helps . . .
Javatm

0
 
LVL 15

Expert Comment

by:Javatm
ID: 11958006
If you want to finalze objects in java here are the examples :
http://www.janeg.ca/scjp/gc/finalize.html
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 92

Expert Comment

by:objects
ID: 11958477
It should run fine, where exactly are you getting poor performance.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11959147
> The desktops at our company are P4 1.8ghz 256MB machines and the application runs absolutely horrendously...
> I mean to the point that the productivity loss to the person using it would make it not worthwhile to use

Also check the JVM or JDK versions and codes varies depending on the version.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11959654
You could try changing from SWING to swt(standard widget toolkit).  The SWT library is the tool set used for creating the Eclipse IDE.  See the following links:
http://www.eclipse.org/swt/
http://www.eclipse.org/articles/Article-SWT-Design-1/SWT-Design-1.html
0
 

Author Comment

by:lomidien
ID: 11959655
I ran the Profilers on the application and the hangup seems to be the following:

I have a CardLayout area of the main frame which holds several sub-panels.  These sub-panels are displayed depending on which JTree item is selected at that time.  In my code, I have all of the panels being initialized on startup (10 panels with multiple swing components on each).  What I would like to do is this:  Upon displaying the login screen, which happens before the panels are instantiated, I would like to run the panels instantiations in a separate thread so that it can happen concurrently with the user typing in their password.

I've tried launching it in it's own thread, but it doesn't seem to process concurrently at all...rather the thread waits for some reason.

Any ideas?
0
 
LVL 92

Expert Comment

by:objects
ID: 11959685
What is making the creation of the panels time consuming?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11959981
> I would like to run the panels instantiations in a separate thread so that it can happen concurrently.

I would you do that ? making a seperate thread can add memory consumption and program gets too complicated
if not wisely done. Well depending on how you implemented it. Have you tried removing the thread yet ?
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 11961118
There are many things to consider, including what else is running on these desktop machines that isn't running on your laptop (for example any virus checker software), or any other heavy applications (servers, etc).  Also (as mentioned previously), the JVM differences between the machines, especially the -Xms and -Xmx settings, and the JDK version.

As for wanting to load other parts of the application using a seperate thread, this is standard Swing design (perhaps unfortunately), and there are standard utility classes available to do these sorts of things (SwingUtilities if I remember correctly).  But perhaps we could provide more beneficial responses given the code that is causing the problems.

One other question though, would be how is the application loaded?  As in, is the entire application Swing based, or do you call some form of midtier?  If so, could this be where it is waiting?  And what is it trying to do?

Finally, you say that you've run the profilers, what profilers?  Memory, thread lock-detection or execution profiling?  Or all of the above?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 59
Way to decrease size of apk file 9 69
hibernate example issues from command prompt 10 41
jsp insert to database example 2 24
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question