|
Re: Problem concurrently resolving proxies to same resource [message #970990 is a reply to message #968904] |
Sun, 04 November 2012 13:38 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
David,
By concurrently, you mean on different threads? ResourceSets are not
thread safe (and they are used to resolve proxies). You need a high
level threading policy for concurrent access. If you only need
concurrent read access, you might just try making
resourceSet.getResource synchronized, or you might use
EcoreUtil.resolveAll right after you load the model so that no
additional proxies ever need to be resolved.
On 04/11/2012 1:04 PM, David Jacobson wrote:
> I have two objects, o1 and o2, and they both have a reference to the
> same resource. When o1 and o2 concurrently attempt to resolve their
> proxy to the resource, only o1 is able to resolve. When they attempt
> to resolve sequentially, they are both able to resolve. Any ideas why
> this would happen?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Problem concurrently resolving proxies to same resource [message #973178 is a reply to message #972574] |
Tue, 06 November 2012 05:58 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
David,
Comments below.
On 05/11/2012 7:39 PM, David Jacobson wrote:
> Thanks for the reply. Yes, I mean on different threads, and I only
> need concurrent read access. I'm fairly new to EMF and not sure I
> follow you on synchronizing the getResource call.
Resolving a proxy involves a call to
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(InternalEObject)
which calls org.eclipse.emf.ecore.util.EcoreUtil.resolve(EObject,
ResourceSet) which calls
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(URI,
boolean) which finally calls
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(URI,
boolean) to load the resource to find the resolution in that resource,
so if you synchronized that method you could make proxy resolution
thread safe.
> I'm using the getters generated for attributes from my ecore model, so
> I'm not calling the getResource method directly.
No, not directly, but indirectly, what I outline above in the mechanism
by which you get non-proxy objects back from these calls (as well as
from accessing the element of lists).
> Any of my object types can typically just call their respective getter
> (which contains generated code for calling eResolveProxy) to get the
> resource.
Yes.
> But in the case of trying to get the resource on different threads,
> the generated getter becomes ineffective, only returning the proxy.
Resource loading takes relatively long so with multiple threads doing
the same thing, another thread might well find a resource that's not
fully loaded and hence can't yet resolve the proxy in that resource.
> Is there some way to force the getter to *really* return the resource?
Yes, by sentimentalizing the loading of resources.
> Right now I have a workaround where each object just keeps trying to
> get the resource until the resource that is returned is no longer a
> proxy, but having to add this to all of my object types is pretty ugly.
That's way too ugly. Do you have complete control over the resource set
that's being used, i.e., you create it?
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.01715 seconds