将 RMI 代理与 Swing 组件一起使用时性能不佳

发布于 2024-09-02 02:29:26 字数 720 浏览 3 评论 0原文

当我将 RMI 代理引用添加到 Java Swing JList 组件时,我遇到了巨大的性能问题。

我正在使用 RMI 从服务器检索用户配置文件列表。检索本身只需要一秒钟左右,因此在这种情况下这是可以接受的。但是,当我尝试将这些代理添加到 JList 时,在自定义 ListModelCellRenderer 的帮助下,需要 30- 60 秒添加约 180 个对象。由于它是用户姓名的列表,因此最好按字母顺序显示。

最大的性能影响是当我将元素添加到 ListModel 时对其进行排序。由于列表始终是排序的,因此我选择使用内置的 Collections.binarySearch() 来查找要添加的下一个元素的正确位置,并且比较器使用定义的两个方法通过 Profile 接口,即 getFirstName()getLastName()

有什么方法可以加快这个过程,或者我只是以错误的方式实现它?或者这是RMI的一个“特性”?我真的很希望能够在本地缓存远程对象的一些数据,以最大程度地减少远程方法调用。


更新和可能的解决方案:我创建了实现远程接口并包含对远程对象的引用的本地类。速度的提高是显而易见的,而且现在工作得非常顺利(至少到目前为止)。我希望这对于我们在应用程序中使用的其他接口同样有效。感谢您的意见,我认为这些意见对我有帮助。

I'm having huge performance issues when I add RMI proxy references to a Java Swing JList-component.

I'm retrieving a list of user Profiles with RMI from a server. The retrieval itself takes just a second or so, so that's acceptable under the circumstances. However, when I try to add these proxies to a JList, with the help of a custom ListModel and a CellRenderer, it takes between 30-60 seconds to add about 180 objects. Since it is a list of users' names, it's preferrable to present them alphabetically.

The biggest performance hit is when I sort the elements as they get added to the ListModel. Since the list will always be sorted, I opted to use the built-in Collections.binarySearch() to find the correct position for the next element to be added, and the comparator uses two methods that are defined by the Profile interface, namely getFirstName() and getLastName().

Is there any way to speed this process up, or am I simply implementing it the wrong way? Or is this a "feature" of RMI? I'd really love to be able to cache some of the data of the remote objects locally, to minimize the remote method calls.


Update and possible solution: I created local classes that implements the remote interfaces and contains a reference to the remote objects. The speed enhancement is noticeable and it now works seemlessly (at least so far). I hope this works equally as well for the other interfaces we use in our application. Thanks for the input that I think helped guide me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏夜暖风 2024-09-09 02:29:26

我认为您需要将显示字段添加到您的配置文件对象中,并将它们与配置文件一起返回。可以在单个检查器视图中带回整个配置文件,但如果您将它们放在概述视图中,则应该将它们带回初始查询中。

I think that you need to add the display fields to your Profile object and return them with the profile. Its fine to bring back the entire Profile in a single inspector view, but if you have them in an overview view you should bring them back in the initial query.

对你的占有欲 2024-09-09 02:29:26

Patrick,您是否在 Remote 对象上调用 Collections.binarySearch ?如果此方法必须向 rmi 服务器询问有关对象的更多信息,则可能会无意中在网络上造成大量流量。

Patrick, are you calling Collections.binarySearch on Remote objects? It may be that you are inadvertantly causing a huge amount of traffic across the network if this method has to ask the rmi server for further information about the objects.

往事随风而去 2024-09-09 02:29:26

(a) 与RMI无关。

(b) 花时间使用binarySearch()只是浪费时间。使用 Collections.sort() 首先或最后对项目进行排序,或者将 TreeModel 基于本质上排序的集合。

(a) It has nothing to do with RMI.

(b) Faffing around with binarySearch() is just wasting time. Sort the items first, or last, with Collections.sort(), or base your TreeModel on an intrinsically sorted collection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文