简体   繁体   English

Java Swing - UI Freezing

[英]Java Swing - UI Freezing

I'm doing some routine in Java (1.5)+Swing, that damands some time. 我在Java(1.5)+ Swing中做了一些例程,这需要一些时间。 How the best way to implement this routing outside the swing thread, to avoid UI freezing? 如何在swing线程之外实现此路由的最佳方法,以避免UI冻结?

Thanks in advance 提前致谢

At first blush, look at the SwingWorker class. 乍一看,请查看SwingWorker类。 When you want to make the code more robust and testable, you probably want to move away from that, but it is a good enough first start. 当你想让代码更健壮和可测试时,你可能想要远离它,但这是一个很好的第一次启动。

You can get a version for Java 1.5 here . 您可以在此处获取Java 1.5的版本。 With 1.6 it is part of the standard API. 使用1.6,它是标准API的一部分。

Using SwingWorker is of course good idea and I recommend that. 使用SwingWorker当然是个好主意,我建议这样做。 Also writing custom javax.swing.Timer s and java.lang.Thread s . 还编写自定义javax.swing.Timerjava.lang.Thread

But don't forget to use profiler - it can help you to find many problems. 但不要忘记使用分析器 - 它可以帮助您找到许多问题。 Like Swing is often having trouble with "dead" Listeners holding some references which can not be garbage collected (resulting in very slow responses or freezing of UI or even memory leaks). 像Swing一样, “死”的监听器经常遇到一些问题,这些监听器持有一些不能被垃圾收集的引用(导致响应非常缓慢或者UI冻结甚至内存泄漏)。 Profiler will help you to investigate memory needs of specific situations when using your application and therefore you might be able to do fine tuning of your app. Profiler将帮助您在使用应用程序时调查特定情况下的内存需求,因此您可以对应用程序进行微调。

Resolved as comment: 解析为评论:

"This could help: stackoverflow.com/questions/2564388/javas-swing-threading – Andreas_D Jul 5 at 22:01" “这可能有所帮助: stackoverflow.com/questions/2564388/javas-swing-threading - Andreas_D 7月5日22:01”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM