简体   繁体   English

Codenameone并发或同步访问数据结构

[英]Codenameone concurrent or synchronized access to data structure

I noticed that the java.util.concurrent package is not included as part of CN1 subset of Java. 我注意到java.util.concurrent包未包含在Java的CN1子集中。 On the other hand, I noticed that the CN1 lib includes ConcurrentModificationException located in java.util package. 另一方面,我注意到CN1库包含位于java.util包中的ConcurrentModificationException。

  1. Why is the concurrent package not included ? 为什么不包含并发包? Are there any technical reasons I am not aware of? 有我不知道的技术原因吗?
  2. How can I guarantee that I don't run into hard-to-debug concurrency issues? 如何保证不会遇到难以调试的并发问题?

The concurrency package was added late to Java and the language supported concurrent access well before that through the synchronized keyword and other language level semantics. 天色已晚加入的Java并发包和语言支持以及之前通过并发访问synchronized关键字等语言水平的语义。

ConcurrentModificationException has nothing to do with the concurrent package as it relates to the collections API. ConcurrentModificationException与并ConcurrentModificationException无关,因为它与collections API有关。 There are many strategies to dealing with concurrent access to shared resources and this all depends on the case you are dealing with but here are a couple of important distinctions: 处理共享资源的并发访问有许多策略,所有这些都取决于您要处理的情况,但是这里有两个重要的区别:

  • Creating threads on the device is bad. 在设备上创建线程是不好的。 You don't have many cores at your disposal and even if you run in a separate thread it will impact UI performance so you should minimize thread creation for performance. 您没有很多核心可以使用,即使您在单独的线程中运行,也会影响UI性能,因此应尽量减少线程创建以提高性能。 Codename One takes this strategy internally by doing almost everything on the EDT hence avoiding the overhead of thread synchronization and sanitizing the native thread access for portability https://www.codenameone.com/manual/edt.html Codename One通过在EDT上执行几乎所有操作来在内部采用此策略,从而避免了线程同步的开销,并为可移植性而对本机线程访问进行了清理,以实现可移植性https://www.codenameone.com/manual/edt.html

  • We do networking on network threads but provide builtin API's & callbacks that go back into the EDT. 我们在网络线程上进行联网,但提供内置的API和回调,这些回调可追溯到EDT中。 That mechanism is also exposed by the simplified Easy Thread class 简化的Easy Thread类也公开了该机制。

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

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