为什么大多数的UI框架单线程? [英] Why are most UI frameworks single threaded?

查看:121
本文介绍了为什么大多数的UI框架单线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,的Java Swing和Android的用户界面都使用单线程模型,其中一个UI线程负责更新所有的UI。是什么使框架设计者选择一个线程模型比其他?

难道多线程UI模型可能给你尽管在更多的复杂性成本更高的性能?我认识到,后者是一个大问题,因为线程相关的bug是的讨厌的,但我想知道是否有任何其他的优点,以单线程模式不是简单等?

解决方案
  

是什么让框架的设计者选择了一个线程模型比其他?

马的嘴

  

AWT最初公开为正常   多线程Java库。但是,随着   在Java团队看了看经验   与AWT和与死锁和   种族的人遇到过,我们   开始认识到,我们在做一个   我们承诺无法跟上。

     

本分析中的一个高潮   设计审查的秋千在1997年,   我们回顾了AWT的播放状态,   和整体的行业经验,   我们接受了秋千团队   建议摇摆应该   仅支持非常有限   多线程技术。

(阅读整篇文章,它解释了非常详细的决定,并指出,以单线程模式完全一样的问题,并最终举动甚至更早发生在Xerox PARC - 在几乎所有我们考虑前沿现代的地方在CS被发明30年前)

  

难道不是多线程UI模型   可能给你更多的表现   尽管在更多的复杂性为代价?

绝对不是,因为绘制的图形用户界面和处理用户动作(这一切都在UI线程需要做的),是不是要在任何理智的2D应用程序的瓶颈。

For example, Java Swing and Android UI both use a single threaded model where a single UI thread is responsible for updating all the UI. What made the framework designers chose one thread model over the other?

Wouldn't multiple threaded UI model potentially give you more performance albeit at the cost of more complexity? I realize that the latter is a big deal because thread related bugs are nasty but I am wondering if there are any other advantages to single-threaded model other than simplicity?

解决方案

What made the framework designers chose one thread model over the other?

From the horse's mouth:

AWT was initially exposed as a normal multi-threaded Java library. But as the Java team looked at the experience with AWT and with the deadlocks and races that people had encountered, we began to realize that we were making a promise we couldn't keep.

This analysis culminated in one of the design reviews for Swing in 1997, when we reviewed the state of play in AWT, and the overall industry experience, and we accepted the Swing team's recommendation that Swing should support only very limited multi-threading.

(Read the whole article, it explains the decision in great detail and states that the exact same problems and eventual move to a single-threaded model had even occured earlier at Xerox PARC - the place where almost everything we consider bleeding edge modern in CS was invented 30 years ago)

Wouldn't multiple threaded UI model potentially give you more performance albeit at the cost of more complexity?

Absolutely not, because drawing the GUI and processing user actions (which is everything the UI thread needs to do) is not going to be the bottleneck in any sane 2D application.

这篇关于为什么大多数的UI框架单线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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