一段时间后,Java Swing GUI变得无法响应 [英] Java Swing GUI becomes unresponsive after a while

查看:398
本文介绍了一段时间后,Java Swing GUI变得无法响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java Swing制作了一个下载管理器。一段时间后,GUI变得无法响应。每次下载都是作为新线程实现的。仅在事件调度线程上运行GUI更新。一般来说,如何改善swing程序的GUI性能呢?还有什么好的工具可以在C中制作GUI吗?



大喊大叫删除[/编辑]

I made a Download Manager using Java Swing. The GUI becomes unresponsive after a while. Every download is implemented as a new thread. Only the GUI updates are run on the Event Dispatch Thread. How can I improve GUI performance of a swing program, in general. Also are there any good tools to make GUIs in C?

Shouting removed[/Edit]

推荐答案

有很多东西可以使一个过程,而不仅仅是一个UI组件,没有响应。解决方案取决于导致问题的原因。这是需要分析和调试的经典案例。



首先要做的是看看你是否可以重现这个问题。从你的帖子听起来这种情况经常发生。问问自己是由特定事件引发的吗?您是否突然下载了特定类型的文件或大型文件?如果您可以找到一个复制步骤,它将使测试任何解决方案变得更加容易。



接下来,检查进程错误时的配置文件。 CPU是否被大量使用?如果是这样,它表示死循环,而不是永远不会退出。也许没有CPU使用情况表明线程挂起等待永远不会发出的通知。



三,检查你的内存配置文件。内存使用量是否超过正常运行?如果是这样,应用程序试图在堆上分配大量内存,这需要花费时间或尝试释放它,以便占用JVM。



当你得到一个想法,尝试记录进程 - 在每个大型运行函数的入口和出口点写入消息,看看是否有一个或多个开始花费更多时间。
There are many things that can make a process, not just a UI component, unresponsive. The solution depends upon what is causing the problem. This is a classic case of needing to analyse and debug.

First thing to do is see if you can reproduce the problem. From your post it sounds like this happens regularly. Ask yourself is it triggered by a specific event? Are you suddenly downloading a particular type of file or large sized file? If you can find a reproduction step it will make testing any solution that much easier.

Next up, examine the profile of the process when it bugs out. Is the CPU being used heavily? If so it indicates a dead loop than can never be exited. Maybe there is no CPU usage which indicates that the thread is hung waiting for a notify that never comes.

Thirdy, check your memory profile. Is memory usage excessive relative to normal running? If so is the app trying to allocate a large swath of memory on the heap that is taking time or trying to release it so tying up the JVM.

When you get an idea, try logging the process - write messages at entry and exit points for each large running function, see if one or more is beginning to take more time.


这篇关于一段时间后,Java Swing GUI变得无法响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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