Java JTable频繁更新? [英] Java JTable with frequent update?

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

问题描述

我正在编写一个能够处理频繁更新的JTable。通常,这个JTable有大约1000行数据,而且有些列会经常更新,因为它们的价值来源于在市场时间内移动很多的股票价格。

I'm coding a JTable that is capable of handling frequent updates. Typically this JTable has ~1000 rows of data, and some of the columns will update frequently because their values are derived from stock price which moves a lot during market hours.

我面临的问题是当大量的行(例如80%)正在更新时,JTable变得非常慢,持续20-30秒左右,分析器显示EDT线程非常繁忙,处理tableChanged调用。

The problem I'm facing is that when large # of rows (e.g. 80%) are updating, the JTable become very slow for 20-30 seconds or so, which the profiler shows that the EDT thread is extremely busy, handling tableChanged calls.

我尝试将更改折叠
1)抑制fireTableCellUpdated
2)如果有< = 50行更改,请在个别方面调用fireTableRowUpdate rows
3)如果有超过50行的更改,请为整个表调用fireTableDataChanged。

I try to collapse the changes by 1) suppressing fireTableCellUpdated 2) If there are <= 50 rows changes, call fireTableRowUpdate on individual rows 3) If there > 50 rows of changes, calling fireTableDataChanged for the entire table.

这是更好的,但是当频繁更新时仍然很慢,我的理解是fireTableDataChanged也很慢。因此,如果数据更新频繁,将频繁调用fireTableDataChanged,并且GUI会感觉迟钝。

It's better, but still slow when there are frequent updates, my understanding is that fireTableDataChanged is slow as well. So if data updates frequent enough, fireTableDataChanged will be called frequently, and the GUI will feel sluggish.

在这个主题上有经验的人是否可以推荐使用fireTableRowsUpdate,
fireTableDataChanged和fireTableStructureChanged的最佳实践来提高GUI的活力和性能?如果您有指向解决此问题的示例代码的指针,它会更好。

Can someone experienced in this subject recommend a best practice in using fireTableRowsUpdate, fireTableDataChanged and fireTableStructureChanged to improve GUI liveliness and performance? If you have pointers to sample codes that address this problem it'll be even better.

非常感谢

Anthony Si

Anthony Si

推荐答案

我已经这样做了,实际上,即使在强大的设置上,默认的JTable性能也非常糟糕。但是所有希望都不会丢失:使用(相当)一些技巧可以获得可接受的性能。

I've done that and indeed, even on beefy setups the default JTable perfs are terribly bad. But all hope is not lost: using (quite) a few tricks you can get acceptable performances.

基本上,Oracle有一个专门用于此目的的教程称为圣诞树 。

Basically, Oracle has a tutorial precisely for this purpose called the "Christmas tree".

在这里,如何创建表现良好的经常更新的JTable:

Here you go, "How to create frequently updated JTable that perform well":

http://www.oracle.com/technetwork/java/christmastree-138396.html

我发现真正令人惊奇的一件事就是不断显示所使用的内存:你可能想要这样做。

One of the thing that I found really amazing was to constantly display the memory used: you may want to do that.

你会惊讶于一个默认的JTable产生了多少不必要的垃圾,减慢了所有的速度,当然GC的触发方式比它应该更频繁。

You'll be amazed at how much needless crap is generated by a default JTable, slowing everything down and making of course the GC trigger way more often than it should.

然后开始实施我给你的链接中给出的所有技巧,你会发现一切都将运行更顺畅。我现在正在运行非常复杂和不断更新的JTable,现在一切都很好:)

Then start implementing all the tricks given in the link I gave you and you'll see that everything shall run much smoother. I'm now running very complex and "constantly updated" JTable and all is fine now :)

但是,除了最简单的情况和少量的数据,默认的JTable实现非常糟糕。

But yup, besides for the simplest case and tiny amounts of data, the default JTable implementation is really terribly bad.

这篇关于Java JTable频繁更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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