Need advice on addressing thread safety of EMF objects #63
Replies: 1 comment 3 replies
-
|
You should consider using MinimalEObjectImpl.Container as the base class. That is the current default for new models. It implements the adapters list differently as well... There exists no magic thread-safety bullet. Even if the list implementation is thread safe, this code cannot guarantee that x will not be added twice: Generally thread safety comes from high level management of how which threads have access to the models and how they access the models. The EMF Transaction framework has the notion of read and write transactions. Xtext and similar concepts. We're more careful with the Ecore model to "freeze" it org.eclipse.emf.ecore.impl.EModelElementImpl.freeze() before many threads start using it. You might reflectively call eGet on all features to initialize the list fields... |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hi. We have many Java packages and types generated from .ecore models. The generated classes directly or indirectly extend EObjectImpl. We cache instances and currently always return a copy of instances retrieved from the cache (even though we set and enforce that such instances are immutable). We'd like to avoid making these copies, but it seems like there are thread safety issues even if only getters are called on the returned instances due to lazy initialization done for some fields (e.g., EObjectImpl.eAdapters(), but there are many other examples in our own generated classes that extend it).
How is this generally handled? Does anyone have any insights into how to get around this?
Are there any levers we can pull at the EMF runtime or codegen level to make things thread safe?
Beta Was this translation helpful? Give feedback.
All reactions