Java性能问题 [英] Java performance problem

查看:89
本文介绍了Java性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我开发了一个与数据库交互的java应用程序。

现在我有了以下问题:


- 我有一个从数据库中检索到的列表(大约200条记录);

- 对于每个,我做一个由html字符串构造的Jlabel;

- 对于每个JLabel我构建一个JPanel e将它添加到主面板。


这个工作正常,但是当应用程序中不活动时

(约30分钟),主要面板消失和应用程序

冻结。我不知道原因(也许是缺乏记忆性的

???)。该应用程序运行在PIII 600mhz,内存为256 mb。


有人可以帮帮我???


谢谢。

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.

推荐答案

嗯?我不能想为什么它会挂30分钟,200条记录并不是很好的数据。我之前看过java渲染HTML JLabel(但是

不是那么慢!)。


你试过删除html,只需使用纯文本在你的JLabels中?

大概是你在使用HTML,因为你想要一些很好的格式化你的

JLabels ..?


您是否尝试将Resultset值添加到JTable中?


-


** http://www.tabletoolkit.com **

将JTable聚合到任意级别以创建自己的枢轴表

" Jos?卡多佐" <乔******** @ yahoo.com>在留言中写道

news:7e ************************** @ posting.google.c om ...
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...


我开发了一个与数据库交互的java应用程序。
现在我遇到了以下问题:
- 我有一个从数据库中检索到的列表(大约200条记录);
- 对于每一个,我做一个由html字符串构造的Jlabel;
- 为每个JLabel构建一个JPanel e将它添加到主要面板。

这个工作正常,但是当应用程序不活动时(大约30分钟),主面板消失,应用程序冻结。我不知道原因(也许是缺乏记忆
???)。应用程序运行在PIII 600mhz,内存为256 mb。

有人可以帮助我???

谢谢。
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.



>嗯?我不能想为什么它会挂30分钟,200条记录不会
> Um? I can''t think why it would hang for 30 minutes, 200 records doesn''t
听起来像很多数据。我之前看过java渲染HTML JLabel(但不是那么慢!)。

您是否尝试删除html,只需在JLabel中使用纯文本?
大概是你正在使用HTML,因为你想在你的
JLabels中有一些很好的格式化吗?

你是否尝试过将Resultset值添加到JTable中?
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?




不,我需要为每一行显示很多信息,这就是为什么我选择html。


我的程序是这样的。


公共class1 {


公共class1(){

...

}


public list1(){

//为每行创建一个JButton

//每个按钮列表器创建第二个对象 - > class2 c2 = new class2()

c2.list2();

}


}

公共class2 {


公共class2(){

...

}


public list2(){

//为每一行创建一个JLabel

}

}


我看到了我的任务管理员,我的内存为javaw.exe达到40.000 kb,

当我运行程序并输入list2时。


然后每当我调用list2时,javaw的内存开始上升到80.000kb。


好​​像他没有为对象释放内存创建。



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.


jo ******** @ yahoo .com (Jos?Cardoso)在留言新闻中写道:< 7e ************************** @ posting.google。 com> ...
jo********@yahoo.com (Jos? Cardoso) wrote in message news:<7e**************************@posting.google. com>...


我开发了一个与数据库交互的java应用程序。
现在我遇到了以下问题:

- 我有一个从数据库中检索到的列表(大约200条记录);
- 对于每一个,我做一个由html字符串构造的Jlabel;
- 对于每个JLabel我构造一个JPanel e将它添加到主面板。

这样可以正常工作,但是当应用程序不活动时(大约30分钟),主面板消失并且应用程序<冻结。我不知道原因(也许是缺乏记忆
???)。应用程序运行在PIII 600mhz,内存为256 mb。

有人可以帮助我???

谢谢。
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.




您好,

也许您正在进行列表检索和JLabel创建权限
Swing线程中的
。这可以解释冻结。您可能希望在单独的线程中执行列表检索。 JLabels的创建可能最好在一个单独的线程中完成,尽管Sun显然

建议最好在Swing线程中创建UI组件
$在某些情况下b $ b。然后让Swing线程重新绘制窗口

(例如使用invokeLater())。


博客:
http://www.clientjava.com/blog/2004/ .. .059428000.html

提供了一个很好的解决Swing类线程问题的方法。


Javalpha。



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.


这篇关于Java性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆