为什么选择SwingWorker?为什么不只是Thread或Runnable? [英] Why SwingWorker? Why not just Thread or Runnable?

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

问题描述

使用 SwingWorker 代替 Thread Runnable 有什么优势?

What are the advantages of using SwingWorker instead of Thread or Runnable?

推荐答案

线程和Runnable是Java 1.0的一部分;他们和当时一样出色.

Thread and Runnable were part of Java 1.0; they're as good as they were back then.

从那时起,新的并发类将提炼出所有有关多线程的知识(感谢您,Doug Lea和其他人).编写多线程代码非常困难.包括SwingWorker在内的新的并发类都试图使其变得更容易.

The new concurrency classes distill all that's been learned about multi-threading since then (thank you, Doug Lea and others). Writing multi-threaded code is terribly difficult. The new concurrency classes, including SwingWorker, try to make that easier.

首先要注意强类型的泛型.有内置的机制可以发布和处理最终结果和中间结果.

Start by noting the generics for strong typing. There's a mechanism built in to publish and process both final and intermediate results.

可以使用Thread和Runnable来模仿它们,但是SwingWorker已经为您完成了.

It'd be possible to mimic these with Thread and Runnable, but SwingWorker has done it for you.

这篇关于为什么选择SwingWorker?为什么不只是Thread或Runnable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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