SwingWorker的基本原理是什么? [英] What is the rationale of SwingWorker?

查看:336
本文介绍了SwingWorker的基本原理是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我可以阅读的内容,它用于在swing应用程序中调度新线程以执行某些后台工作,但是使用它而不是普通线程有什么好处?

For what I can read, it is used to dispatch a new thread in a swing app to perform some "background" work, but what's the benefit from using this rather than a "normal" thread?

使用新线程是不是一样,当它完成时使用SwingUtilities.invokeLater调用一些GUI方法?...

Is not the same using a new Thread and when it finish invoke some GUI method using SwingUtilities.invokeLater?...

什么是我在这里失踪了?

What am I missing here?

http:// en .wikipedia.org / wiki / SwingWorker

http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

推荐答案

是的,你可以完成SwingWorker对vanilla线程+ invokeLater的处理。 SwingWorker提供了一种可预测的集成方式,可以在后台线程上完成任务并在EDT上报告结果。 SwingWorker还增加了对中间结果的支持。同样,您可以自己完成所有这些,但有时可以轻松使用集成且可预测的解决方案,尤其是在并发方面。

Yes, you can accomplish what a SwingWorker does with vanilla threads + invokeLater. SwingWorker provides a predictable, integrated way to accomplish tasks on a background thread and report result on the EDT. SwingWorker additionally adds support for intermediate results. Again, you can do all of this yourself but sometimes it's easy to use the integrated and predictable solution especially when it comes to concurrency.

这篇关于SwingWorker的基本原理是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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