gpt4 book ai didi

java - 为什么 Swing 不是 "thread safe"?

转载 作者:行者123 更新时间:2023-12-01 06:37:48 27 4
gpt4 key购买 nike

在关于线程的 Java 类(class)的最后几分钟,我们的教授建议我们在开发复杂的基于 Swing 的应用程序时要特别注意,因为 Swing不是线程安全的。这背后有什么具体原因吗? Swing由于设计决策或软件限制而不是线程安全的?预先感谢您的回答。

最佳答案

Javin Poul 的编程博客 Java Revisiteda great blog post关于此:

Why Swing is not thread-safe in Java?

It's the decision taken by there designer, at that time. Since making an API thread-safe takes a lot of work, and it's often based upon benefit you get. Since GUI screens are mostly updated in response of user action e.g. when user click a button, and since events are handled in the same Event dispatcher thread, it's easy to update GUI on that thread. It's very rare, when an update request for GUI comes from a different thread e.g. may be once a network request is complete or a file is loaded.

关于java - 为什么 Swing 不是 "thread safe"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39306022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com