Solved

Swing Performance

Posted on 2004-09-01
10
205 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now