EventQueue.invokeLater和Thread.start [英] EventQueue.invokeLater vs Thread.start

查看:147
本文介绍了EventQueue.invokeLater和Thread.start的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Swing应用程序,我们使用EventQueue.invokeLater()是否有原因? Thread.start()是否应该以相同的方式工作?

For Swing applications, is there a reason we use EventQueue.invokeLater()? Should't Thread.start() work the same way?

Thread.start的另一个优点是我们可以告诉线程中断,因为EventQueue.invokeLater没有为我们提供Thread对象.

Another advantage of Thread.start is we have a way of telling the thread to interrupt as EventQueue.invokeLater does not provide us with the Thread object.

推荐答案

由于Swing是单线程的,因此应将EventQueue.invokeLater用于所有GUI更新.请参见 http://docs.oracle. com/javase/6/docs/api/javax/swing/package-summary.html#threading

You should use EventQueue.invokeLater for all GUI updates since Swing in a way is singlethreaded. See http://docs.oracle.com/javase/6/docs/api/javax/swing/package-summary.html#threading

您可以启动线程进行计算等,但是应该使用invokeLater更新GUI.

You can start threads to do calculations etc, but should update the GUI using invokeLater.

这篇关于EventQueue.invokeLater和Thread.start的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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