简体   繁体   English

如果我在非EDT的单个线程上处理GUI,它仍然是线程安全的吗?

[英]If I handle a GUI on a single thread that is not the EDT, is it still thread safe?

If I create a GUI on a different thread, and make sure that any updates that happen to the GUI occur on that thread and that thread only- is it then still thread safe? 如果我在其他线程上创建GUI,并确保对该GUI进行的任何更新仅在该线程上发生并且仅在该线程上发生-那么它仍然是线程安全的吗? I know this would be difficult to ensure, so in a way I'm kind of asking: Is there anything special/different about the EDT compared to other threads? 我知道很难确保这一点,因此我在某种程度上会问:与其他线程相比,EDT是否有什么特殊/不同之处?

Keep in mind I'm not asking about good practices or other solutions to this problem, I'm asking if, on a purely technical level, if you basically treated a thread like the EDT, would the GUI created on the new thread be safe to use? 请记住,我不是在询问有关此问题的良好实践或其他解决方案,而是在纯粹的技术层面上询问,如果您基本上将诸如EDT之类的线程视为,在新线程上创建的GUI是否安全?使用?

It is not thread safe because your processes are not the only one that read/write UI element. 它不是线程安全的,因为您的进程不是唯一读/写UI元素的进程。 JRE is also read and write but it does it via EDT. JRE也可以读写,但可以通过EDT进行。 So even if you read/write in the single thread which is not EDT there are processes that do it in EDT - so you end up with one UI element, few threads, no synchronization. 因此,即使您在非EDT的单个线程中进行读取/写入,也有在EDT中执行此操作的进程-因此您最终只能得到一个UI元素,几个线程,没有同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM