本文介绍了为什么Swing线程模型被认为是错误的,应该如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我多次听说Java Swing线程模型是错误的。我不完全理解为什么,我知道这个问题与你可以从主UI线程以外的另一个线程中绘制 Drawable 的事实有关。我知道有一些实用功能,比如 SwingUtilities.invokeAndWait SwingUtilities.invokeLater 可以让你在 Runnable ,它又由Event Dispatcher线程运行。我猜这种方式可以确保绘画是同步完成的,这不会使缓冲区处于不稳定的状态。

I heard many times that Java Swing threading model is wrong. I don't fully understand why, I know that the problem is related to the fact that you can draw on a Drawable from another thread other than the main UI thread. I know that there are utility functionalities like SwingUtilities.invokeAndWait and SwingUtilities.invokeLater that let you do your painting in a Runnable, that in turn is run by the Event Dispatcher thread. I guess that this way you ensure that painting is done synchronously and this doesn't leave the buffer in an incosistent state.

我的问题是:好的UI工具包的行为如何?采用了哪些解决方案?

My question is: how do "good" UI toolkits behave? What solutions are adopted?

推荐答案

Brian Goetz的,

Brian Goetz's Java Concurrency in Practice,

9.1为什么GUI是单线程的?

这篇关于为什么Swing线程模型被认为是错误的,应该如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:38