473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Java performance problem

Hi,

I have developed a java application that interacts with a database.
Now i've the folowing problem:

- I have a list retrieved from the database(about 200 records);
- for each, i do a Jlabel constructed from an html String;
- for each JLabel i construct a JPanel e add it to the main panel.

this works fine, but when there's an inactivity in the application
(about 30 minutes), the main panel disapear and the application
freeze. i don't know the reason for that (perhaps a lack of memomy
???).The application runs in a PIII 600mhz with 256 mb of ram.

Somebody can help me???

Thanks.
Jul 17 '05 #1
11 3512
Um? I can't think why it would hang for 30 minutes, 200 records doesn't
sound like much data. I've seen java render HTML JLabel slowly before (but
not that slowly!).

Have you tried removing the html, just use plain text in your JLabels?
Presumably you're using HTML because you want some nice formatting in your
JLabels..?

Have you tried adding your Resultset values into a JTable?

--

** http://www.tabletoolkit.com **
Aggregate a JTable to an arbitrary level to create your own pivot tables
"Jos? Cardoso" <jo********@yahoo.com> wrote in message
news:7e**************************@posting.google.c om...
Hi,

I have developed a java application that interacts with a database.
Now i've the folowing problem:

- I have a list retrieved from the database(about 200 records);
- for each, i do a Jlabel constructed from an html String;
- for each JLabel i construct a JPanel e add it to the main panel.

this works fine, but when there's an inactivity in the application
(about 30 minutes), the main panel disapear and the application
freeze. i don't know the reason for that (perhaps a lack of memomy
???).The application runs in a PIII 600mhz with 256 mb of ram.

Somebody can help me???

Thanks.

Jul 17 '05 #2
> Um? I can't think why it would hang for 30 minutes, 200 records doesn't
sound like much data. I've seen java render HTML JLabel slowly before (but
not that slowly!).

Have you tried removing the html, just use plain text in your JLabels?
Presumably you're using HTML because you want some nice formatting in your
JLabels..?

Have you tried adding your Resultset values into a JTable?


No, i need to show a lot of information for each row, thats why i choose html.

My program is something like that.

public class1{

public class1(){
...
}

public list1(){
// creates a JButton for each row
// each button listner creates a 2nd object -> class2 c2 = new class2()
c2.list2();
}

}

public class2{

public class2(){
...
}

public list2(){
// creates a JLabel for each row
}
}

I was seeing my taskmanager, and my memory goes to the 40.000 kb for javaw.exe,
when i run the program and enter in list2.

Then every time that i call list2, memory for javaw starts goes up to 80.000kb.

It seems like he isn't releasing the memory for objects created.
Jul 17 '05 #3
jo********@yahoo.com (Jos? Cardoso) wrote in message news:<7e**************************@posting.google. com>...
Hi,

I have developed a java application that interacts with a database.
Now i've the folowing problem:

- I have a list retrieved from the database(about 200 records);
- for each, i do a Jlabel constructed from an html String;
- for each JLabel i construct a JPanel e add it to the main panel.

this works fine, but when there's an inactivity in the application
(about 30 minutes), the main panel disapear and the application
freeze. i don't know the reason for that (perhaps a lack of memomy
???).The application runs in a PIII 600mhz with 256 mb of ram.

Somebody can help me???

Thanks.


Hi,
Perhaps you are doing the list retrieval and JLabel creation right
in the Swing thread. That would explain the "freeze". You may want to
do the list retrieval in a separate thread. The creation of JLabels is
probably best done in a separate thread as well, though Sun apparently
recommends that UI components are best created in the Swing thread
under some situations. Then get the Swing thread to repaint the window
(using invokeLater(), for example).

The blog:
http://www.clientjava.com/blog/2004/...059428000.html
presents an excellent approach to class threading problems with Swing.

Javalpha.
Jul 17 '05 #4
On 30 Aug 2004 11:16:13 -0700, Jos? Cardoso wrote:
No, i need to show a lot of information for each row, thats why i choose html.


have you considered/tried convertint that table to
a JList? A JList can accept a custom ListCellRenderer,
and AFAIU, only the items in the visible area are liable
to get the HTML overhead..

HTH

comp.lang.java,
comp.lang.java.developer,
comp.lang.java.help

Please also note that .developer is not a
valid group* and three groups too many **.

* <http://www.physci.org/codes/javafaq.jsp#groups>
** <http://www.physci.org/codes/javafaq.jsp#xpost>

Follow-Ups set top c.l.j.help only

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #5
> Hi,
Perhaps you are doing the list retrieval and JLabel creation right
in the Swing thread. That would explain the "freeze". You may want to
do the list retrieval in a separate thread. The creation of JLabels is
probably best done in a separate thread as well, though Sun apparently
recommends that UI components are best created in the Swing thread
under some situations. Then get the Swing thread to repaint the window
(using invokeLater(), for example).

The blog:
http://www.clientjava.com/blog/2004/...059428000.html
presents an excellent approach to class threading problems with Swing.

Javalpha.

Hi,
My problem isn't the retrieval, is after that. Java don't release the
memory used during the retrieval, and when the user click on the
button that make the same retrieval, the memory increases and after
that freezes.
Jul 17 '05 #6
I think my problem is in java allocated memory. It uses memory for the
objects created and don't release it. I was working in my application
until he reaches the 80mb of memory, and if i minimize my GUI, the
memory for my process cames to 11mb. Otherwise the memory keeps
climbing and hangs the application.

Is there any way to release the memory or destroy the objects ?
Jul 17 '05 #7
On 31 Aug 2004 08:34:13 -0700, Jos? Cardoso wrote:
I think my problem is in java allocated memory.


Have you tried a JList?
<http://google.com/groups?selm=1rkhi290ye6qx%24.1bzin0hkbcvhy.dlg%404 0tude.net>
There is no need for there to be any more than
a 'screenful' of the HTML (for rendering) at any time..

But, ..by the way, we have not seen an example
of your code, that might be the problem..

Cut out the D/B stuff and create an example
that creates 200 items for rendering using
dummy strings/HTML.

For further tips on an example..
<http://www.physci.org/codes/sscce.jsp>

Now, it seems you may not have got my earlier
reply, you are cross-posting to three groups,
one of which is not valid, *PLEASE* *STOP* *IT*.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #8
jo********@yahoo.com (Jos? Cardoso) wrote in message news:<7e**************************@posting.google. com>...
I think my problem is in java allocated memory. It uses memory for the
objects created and don't release it. I was working in my application
until he reaches the 80mb of memory, and if i minimize my GUI, the
memory for my process cames to 11mb. Otherwise the memory keeps
climbing and hangs the application.

Is there any way to release the memory or destroy the objects ?


Hi, here are some thoughts on how I would approach your problem.
First, try using the "-verbose:gc" option of your JVM, to see whether
the GC runs and, if so, whether it is successful in reclaiming memory.
You can also experiment with the "-Xmx" option to the JVM to increase
the maximum heap size (to say 128 MB) and see whether the allocated
memory saturates at some point. (BTW, the command "java -?" will
display all standard options available while "java -X" will display
non-standard options.)

Secondly, consider nulling out object references when you are sure
they won't be accessed again. CAUTION: Premature nulling is a bug and
may require lots of unit testing to catch via NullPointerExceptions.

Thirdly, consider running the GC under program control using
System.gc(). This is not recommended in general because it is best to
let the JVM decide when to run the GC. You could perhaps run the GC
before each list retrieval. (This is just a thought, I don't know
enough about your app to say whether this is a good idea.)

Finally, consider using garbage collectors other than the defaut. JDK
1.4 includes no less than <a href=
"http://www-106.ibm.com/developerworks/java/library/j-jtp11253/">
6 separate garbage collectors</a>. Without knowing more about your
application, I cannot say whether this will be helpful or which one is
a good candidate to try.
Jul 17 '05 #9
tks for your tips.

after analise my program, i think that i´ve a problem in the
structure.

My program is something like that

public class1{
....
public met1(){
class2 = new class2();
}
}

public class2{
....
public met2(){
class3 = new class3();
}
}

public class3{
....
public met3(){
.....
....
button listener
class1 = new class1();
}
}

when i execute my program he works fine, but the memory allocated for
the process javaw.exe starts climb, he doesn't release the memory
taken.

A strange thing happens when i minimize my gui with the mouse, now he
dealocates the memory take by the process.... i don't understand why.
i agree that the structure isn't very good, but i don't see how can i
redefine it. The program should do the folowing:

- have a panel with a list of buttons(machine names) obtained from a
database.
- when we press a button, he must show a list of services for the
selected machine.
- when we choose a service, he must show the material used in that
service.
- after that we press a button and the program must list again the
services(related with the original machine selected).

All this must be showed in the same panel.

This is an appication that runs with a touch screen
tks
Jul 17 '05 #10
On 1 Sep 2004 03:20:55 -0700, Jos? Cardoso wrote:
My program is something like that..


(that doesn't compile.. SSc*C*e)

Did you read that link to the SSCCE?

And, ..now that you seem to have dropped
one of the cross-posted groups, can I
also ask you to drop the invalid group
'comp.lang.java' and follow this up on *only*
comp.lang.java.help Jos?(?)

And please trim your problem down to a
self contained compileable example, there
are good reasons for preparing one, see..
<http://www.physci.org/codes/sscce.jsp>

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 17 '05 #11
Jos? Cardoso wrote:
I think my problem is in java allocated memory. It uses memory for the
objects created and don't release it. I was working in my application
until he reaches the 80mb of memory, and if i minimize my GUI, the
memory for my process cames to 11mb. Otherwise the memory keeps
climbing and hangs the application.


It sounds like you are using Windows Task manager to determine how much
memory you are using. If that is the case, you cannot simply look at
the default memory column that task manager presents. That only
displays the amount of physical memory used by the process (that is why
you see a great reduction when you minimize an application; Windows
swaps out its memory). Use the options of task manager to display the
virtual memory as well.

As an alternative, you can use System.freeMemory(), etc. to get the
information direct from the JVM.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Zach | last post by:
This is all on linux using jdk1.3. My application is written in AWT, no swing. The application requires running it on the host machine and tunneling the GUI back to a client. I've been doing...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
30
by: Mike Cox | last post by:
Hi. I recently ran a benchmark against two simple programs, one written in Java and the other in C++. The both accomplish the same thing, outputting "Hello World" on my screen. The C++ program...
2
by: Rafael Faria | last post by:
Hi All, We are starting a large data warehousing project using DB2 8.2 on AIX. There is a direction to move any new internal development to Java and a question was raised: Would it be a good...
0
by: Lakshmi | last post by:
Hi All, I am having performance issues with the .NET client calling the Java Webservice running on axis. Have detailed the problem below. Please help. I wrote a webservice in Java. Lets name...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.