Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » null as Resource in ResourceSet
null as Resource in ResourceSet [message #534140] Tue, 18 May 2010 08:01 Go to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi all,

we have an EMF model that is persisted in many resources on filesystem. All
these resources are contained in one ResourceSet as EMF resource. The
strange thing is that we get sometimes null-Entries in the resource list of
the resource set. The problem is that we do not really know where the null
entry comes from. We have seen that EMF perfroms Null-Checks before
inserting a resource in the resource set, so it should not be possible to
have null entries in the resource set. Has anybody an idea where these null
entries are coming from? Or does anybody know how to insert a null resource
in the resource set with bypassing the null checks from EMF?

Cheers

Sascha
Re: null as Resource in ResourceSet [message #534205 is a reply to message #534140] Tue, 18 May 2010 10:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:
> Hi all,
>
> we have an EMF model that is persisted in many resources on filesystem. All
> these resources are contained in one ResourceSet as EMF resource. The
> strange thing is that we get sometimes null-Entries in the resource list of
> the resource set. The problem is that we do not really know where the null
> entry comes from. We have seen that EMF perfroms Null-Checks before
> inserting a resource in the resource set, so it should not be possible to
> have null entries in the resource set. Has anybody an idea where these null
> entries are coming from? Or does anybody know how to insert a null resource
> in the resource set with bypassing the null checks from EMF?
>
> Cheers
>
> Sascha
>
>
>
Re: null as Resource in ResourceSet [message #534225 is a reply to message #534205] Tue, 18 May 2010 12:10 Go to previous messageGo to next message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?

Thanks for your help!

Cheers

Sascha


"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hstrsu$cdp$1@build.eclipse.org...
> Sascha,
>
> ResourceSets aren't thread safe so that's a likely source of the problem
> you describe. I've seen, for example, many problems reported from WTP
> about null in the list of adapters and those were definitely caused by
> adding an adapter on two threads at the same time.
>
>
> Sascha Theves wrote:
>> Hi all,
>>
>> we have an EMF model that is persisted in many resources on filesystem.
>> All these resources are contained in one ResourceSet as EMF resource. The
>> strange thing is that we get sometimes null-Entries in the resource list
>> of the resource set. The problem is that we do not really know where the
>> null entry comes from. We have seen that EMF perfroms Null-Checks before
>> inserting a resource in the resource set, so it should not be possible to
>> have null entries in the resource set. Has anybody an idea where these
>> null entries are coming from? Or does anybody know how to insert a null
>> resource in the resource set with bypassing the null checks from EMF?
>>
>> Cheers
>>
>> Sascha
>>
>>
Re: null as Resource in ResourceSet [message #534242 is a reply to message #534225] Tue, 18 May 2010 12:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030704030604070802040101
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Sascha,

Comments below.

Sascha Theves wrote:
> Hi Ed,
>
> thanks for the quick answer! We think that it is caused by a concurrency
> problem too. But we can not imagine where the problem exactly comes from.
> Could you show me some insights of the EMF code where the concurrency
> problem could occur? I think in our case it is somehow caused when we read
> our model in parallel. Some of our containment references are objects that
> are persisted in its own resource. Iterating over these containment
> references causes EMF to resolve proxies. When that happens new resources
> must be added to the resource set. But that is done internally by EMF and
> not in our code. That would mean we can not read our model at the same time
> in two different threads. Am I right?
>
Yes, resolving proxies on multiple threads at the same time will cause
issues. This is one of the things the transaction framework helps with,
i.e., you must create a read transaction. Or you might just specialize
your ResourceSetImpl to add a synchronize to getResource to serialize
access.
> Thanks for your help!
>
> Cheers
>
> Sascha
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hstrsu$cdp$1@build.eclipse.org...
>
>> Sascha,
>>
>> ResourceSets aren't thread safe so that's a likely source of the problem
>> you describe. I've seen, for example, many problems reported from WTP
>> about null in the list of adapters and those were definitely caused by
>> adding an adapter on two threads at the same time.
>>
>>
>> Sascha Theves wrote:
>>
>>> Hi all,
>>>
>>> we have an EMF model that is persisted in many resources on filesystem.
>>> All these resources are contained in one ResourceSet as EMF resource. The
>>> strange thing is that we get sometimes null-Entries in the resource list
>>> of the resource set. The problem is that we do not really know where the
>>> null entry comes from. We have seen that EMF perfroms Null-Checks before
>>> inserting a resource in the resource set, so it should not be possible to
>>> have null entries in the resource set. Has anybody an idea where these
>>> null entries are coming from? Or does anybody know how to insert a null
>>> resource in the resource set with bypassing the null checks from EMF?
>>>
>>> Cheers
>>>
>>> Sascha
>>>
>>>
>>>
>
>
>

--------------030704030604070802040101
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sascha,<br>
<br>
Comments below.<br>
<br>
Sascha Theves wrote:
<blockquote cite="mid:hsu04g$pdn$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?
</pre>
</blockquote>
Yes, resolving proxies on multiple threads at the same time will cause
issues.&nbsp; This is one of the things the transaction framework helps
with, i.e., you must create a read transaction.&nbsp; Or you might just
specialize your ResourceSetImpl to add a synchronize to getResource to
serialize access.<br>
<blockquote cite="mid:hsu04g$pdn$1@build.eclipse.org" type="cite">
<pre wrap="">
Thanks for your help!

Cheers

Sascha


"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext" href="news:hstrsu$cdp$1@build.eclipse.org">news:hstrsu$cdp$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,

we have an EMF model that is persisted in many resources on filesystem.
All these resources are contained in one ResourceSet as EMF resource. The
strange thing is that we get sometimes null-Entries in the resource list
of the resource set. The problem is that we do not really know where the
null entry comes from. We have seen that EMF perfroms Null-Checks before
inserting a resource in the resource set, so it should not be possible to
have null entries in the resource set. Has anybody an idea where these
null entries are coming from? Or does anybody know how to insert a null
resource in the resource set with bypassing the null checks from EMF?

Cheers

Sascha


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------030704030604070802040101--
Re: null as Resource in ResourceSet [message #534575 is a reply to message #534242] Wed, 19 May 2010 14:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.baumgartner.innovations.de

Hi Ed,

I wrote a test case for this (see below). It passes for Resources, but it
really fails if I change it to adapters, just like you told.

Regards
Tim


public class NullResourceTest extends TestCase
{
private ResourceSet set;

private class ResourceThread extends Thread
{
private Resource resource;

public ResourceThread()
{
resource = new XMIResourceImpl();
}

@Override
public void run()
{
if (set.getResources().contains(resource))
{
set.getResources().remove(resource);
}
else
{
set.getResources().add(resource);
}
}
}

@Override
protected void setUp() throws Exception
{
set = new ResourceSetImpl();
}

public void test() throws Exception
{
for (int i = 0; i < 10; i++)
{
new ResourceThread().start();
}
long time = System.currentTimeMillis();
while (System.currentTimeMillis() < time + 10000)
{
if (set.getResources().contains(null))
{
fail("Null in ResourceSet");
}
}
}
}



"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hsu2g3$muh$1@build.eclipse.org...
Sascha,

Comments below.

Sascha Theves wrote:
Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?

Yes, resolving proxies on multiple threads at the same time will cause
issues. This is one of the things the transaction framework helps with,
i.e., you must create a read transaction. Or you might just specialize your
ResourceSetImpl to add a synchronize to getResource to serialize access.

Thanks for your help!

Cheers

Sascha


"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hstrsu$cdp$1@build.eclipse.org...

Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:

Hi all,

we have an EMF model that is persisted in many resources on filesystem.
All these resources are contained in one ResourceSet as EMF resource. The
strange thing is that we get sometimes null-Entries in the resource list
of the resource set. The problem is that we do not really know where the
null entry comes from. We have seen that EMF perfroms Null-Checks before
inserting a resource in the resource set, so it should not be possible to
have null entries in the resource set. Has anybody an idea where these
null entries are coming from? Or does anybody know how to insert a null
resource in the resource set with bypassing the null checks from EMF?

Cheers

Sascha
Re: null as Resource in ResourceSet [message #534579 is a reply to message #534575] Wed, 19 May 2010 15:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Tim,

I don't see any further questions here. Just to be clear: don't expect
anything in EMF to change to provide thread safety. Thread safety needs
to be achieved by a sound threading policy in the application as a
whole, not by judicious sprinklings of synchronized calls; that approach
just interferes with the high-level policy and leads to unavoidable
deadlocks.


Tim Baumgartner wrote:
> Hi Ed,
>
> I wrote a test case for this (see below). It passes for Resources, but it
> really fails if I change it to adapters, just like you told.
>
> Regards
> Tim
>
>
> public class NullResourceTest extends TestCase
> {
> private ResourceSet set;
>
> private class ResourceThread extends Thread
> {
> private Resource resource;
>
> public ResourceThread()
> {
> resource = new XMIResourceImpl();
> }
>
> @Override
> public void run()
> {
> if (set.getResources().contains(resource))
> {
> set.getResources().remove(resource);
> }
> else
> {
> set.getResources().add(resource);
> }
> }
> }
>
> @Override
> protected void setUp() throws Exception
> {
> set = new ResourceSetImpl();
> }
>
> public void test() throws Exception
> {
> for (int i = 0; i < 10; i++)
> {
> new ResourceThread().start();
> }
> long time = System.currentTimeMillis();
> while (System.currentTimeMillis() < time + 10000)
> {
> if (set.getResources().contains(null))
> {
> fail("Null in ResourceSet");
> }
> }
> }
> }
>
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hsu2g3$muh$1@build.eclipse.org...
> Sascha,
>
> Comments below.
>
> Sascha Theves wrote:
> Hi Ed,
>
> thanks for the quick answer! We think that it is caused by a concurrency
> problem too. But we can not imagine where the problem exactly comes from.
> Could you show me some insights of the EMF code where the concurrency
> problem could occur? I think in our case it is somehow caused when we read
> our model in parallel. Some of our containment references are objects that
> are persisted in its own resource. Iterating over these containment
> references causes EMF to resolve proxies. When that happens new resources
> must be added to the resource set. But that is done internally by EMF and
> not in our code. That would mean we can not read our model at the same time
> in two different threads. Am I right?
>
> Yes, resolving proxies on multiple threads at the same time will cause
> issues. This is one of the things the transaction framework helps with,
> i.e., you must create a read transaction. Or you might just specialize your
> ResourceSetImpl to add a synchronize to getResource to serialize access.
>
> Thanks for your help!
>
> Cheers
>
> Sascha
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hstrsu$cdp$1@build.eclipse.org...
>
> Sascha,
>
> ResourceSets aren't thread safe so that's a likely source of the problem
> you describe. I've seen, for example, many problems reported from WTP
> about null in the list of adapters and those were definitely caused by
> adding an adapter on two threads at the same time.
>
>
> Sascha Theves wrote:
>
> Hi all,
>
> we have an EMF model that is persisted in many resources on filesystem.
> All these resources are contained in one ResourceSet as EMF resource. The
> strange thing is that we get sometimes null-Entries in the resource list
> of the resource set. The problem is that we do not really know where the
> null entry comes from. We have seen that EMF perfroms Null-Checks before
> inserting a resource in the resource set, so it should not be possible to
> have null entries in the resource set. Has anybody an idea where these
> null entries are coming from? Or does anybody know how to insert a null
> resource in the resource set with bypassing the null checks from EMF?
>
> Cheers
>
> Sascha
>
>
>
>
>
>
>
>
>
Re: null as Resource in ResourceSet [message #619627 is a reply to message #534140] Tue, 18 May 2010 10:58 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:
> Hi all,
>
> we have an EMF model that is persisted in many resources on filesystem. All
> these resources are contained in one ResourceSet as EMF resource. The
> strange thing is that we get sometimes null-Entries in the resource list of
> the resource set. The problem is that we do not really know where the null
> entry comes from. We have seen that EMF perfroms Null-Checks before
> inserting a resource in the resource set, so it should not be possible to
> have null entries in the resource set. Has anybody an idea where these null
> entries are coming from? Or does anybody know how to insert a null resource
> in the resource set with bypassing the null checks from EMF?
>
> Cheers
>
> Sascha
>
>
>
Re: null as Resource in ResourceSet [message #619628 is a reply to message #534205] Tue, 18 May 2010 12:10 Go to previous message
Sascha Theves is currently offline Sascha ThevesFriend
Messages: 39
Registered: July 2009
Member
Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?

Thanks for your help!

Cheers

Sascha


"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hstrsu$cdp$1@build.eclipse.org...
> Sascha,
>
> ResourceSets aren't thread safe so that's a likely source of the problem
> you describe. I've seen, for example, many problems reported from WTP
> about null in the list of adapters and those were definitely caused by
> adding an adapter on two threads at the same time.
>
>
> Sascha Theves wrote:
>> Hi all,
>>
>> we have an EMF model that is persisted in many resources on filesystem.
>> All these resources are contained in one ResourceSet as EMF resource. The
>> strange thing is that we get sometimes null-Entries in the resource list
>> of the resource set. The problem is that we do not really know where the
>> null entry comes from. We have seen that EMF perfroms Null-Checks before
>> inserting a resource in the resource set, so it should not be possible to
>> have null entries in the resource set. Has anybody an idea where these
>> null entries are coming from? Or does anybody know how to insert a null
>> resource in the resource set with bypassing the null checks from EMF?
>>
>> Cheers
>>
>> Sascha
>>
>>
Re: null as Resource in ResourceSet [message #619629 is a reply to message #534225] Tue, 18 May 2010 12:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030704030604070802040101
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Sascha,

Comments below.

Sascha Theves wrote:
> Hi Ed,
>
> thanks for the quick answer! We think that it is caused by a concurrency
> problem too. But we can not imagine where the problem exactly comes from.
> Could you show me some insights of the EMF code where the concurrency
> problem could occur? I think in our case it is somehow caused when we read
> our model in parallel. Some of our containment references are objects that
> are persisted in its own resource. Iterating over these containment
> references causes EMF to resolve proxies. When that happens new resources
> must be added to the resource set. But that is done internally by EMF and
> not in our code. That would mean we can not read our model at the same time
> in two different threads. Am I right?
>
Yes, resolving proxies on multiple threads at the same time will cause
issues. This is one of the things the transaction framework helps with,
i.e., you must create a read transaction. Or you might just specialize
your ResourceSetImpl to add a synchronize to getResource to serialize
access.
> Thanks for your help!
>
> Cheers
>
> Sascha
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hstrsu$cdp$1@build.eclipse.org...
>
>> Sascha,
>>
>> ResourceSets aren't thread safe so that's a likely source of the problem
>> you describe. I've seen, for example, many problems reported from WTP
>> about null in the list of adapters and those were definitely caused by
>> adding an adapter on two threads at the same time.
>>
>>
>> Sascha Theves wrote:
>>
>>> Hi all,
>>>
>>> we have an EMF model that is persisted in many resources on filesystem.
>>> All these resources are contained in one ResourceSet as EMF resource. The
>>> strange thing is that we get sometimes null-Entries in the resource list
>>> of the resource set. The problem is that we do not really know where the
>>> null entry comes from. We have seen that EMF perfroms Null-Checks before
>>> inserting a resource in the resource set, so it should not be possible to
>>> have null entries in the resource set. Has anybody an idea where these
>>> null entries are coming from? Or does anybody know how to insert a null
>>> resource in the resource set with bypassing the null checks from EMF?
>>>
>>> Cheers
>>>
>>> Sascha
>>>
>>>
>>>
>
>
>

--------------030704030604070802040101
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sascha,<br>
<br>
Comments below.<br>
<br>
Sascha Theves wrote:
<blockquote cite="mid:hsu04g$pdn$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?
</pre>
</blockquote>
Yes, resolving proxies on multiple threads at the same time will cause
issues.&nbsp; This is one of the things the transaction framework helps
with, i.e., you must create a read transaction.&nbsp; Or you might just
specialize your ResourceSetImpl to add a synchronize to getResource to
serialize access.<br>
<blockquote cite="mid:hsu04g$pdn$1@build.eclipse.org" type="cite">
<pre wrap="">
Thanks for your help!

Cheers

Sascha


"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext" href="news:hstrsu$cdp$1@build.eclipse.org">news:hstrsu$cdp$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,

we have an EMF model that is persisted in many resources on filesystem.
All these resources are contained in one ResourceSet as EMF resource. The
strange thing is that we get sometimes null-Entries in the resource list
of the resource set. The problem is that we do not really know where the
null entry comes from. We have seen that EMF perfroms Null-Checks before
inserting a resource in the resource set, so it should not be possible to
have null entries in the resource set. Has anybody an idea where these
null entries are coming from? Or does anybody know how to insert a null
resource in the resource set with bypassing the null checks from EMF?

Cheers

Sascha


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------030704030604070802040101--
Re: null as Resource in ResourceSet [message #619630 is a reply to message #534242] Wed, 19 May 2010 14:52 Go to previous message
Eclipse UserFriend
Originally posted by: tim.baumgartner.innovations.de

Hi Ed,

I wrote a test case for this (see below). It passes for Resources, but it
really fails if I change it to adapters, just like you told.

Regards
Tim


public class NullResourceTest extends TestCase
{
private ResourceSet set;

private class ResourceThread extends Thread
{
private Resource resource;

public ResourceThread()
{
resource = new XMIResourceImpl();
}

@Override
public void run()
{
if (set.getResources().contains(resource))
{
set.getResources().remove(resource);
}
else
{
set.getResources().add(resource);
}
}
}

@Override
protected void setUp() throws Exception
{
set = new ResourceSetImpl();
}

public void test() throws Exception
{
for (int i = 0; i < 10; i++)
{
new ResourceThread().start();
}
long time = System.currentTimeMillis();
while (System.currentTimeMillis() < time + 10000)
{
if (set.getResources().contains(null))
{
fail("Null in ResourceSet");
}
}
}
}



"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hsu2g3$muh$1@build.eclipse.org...
Sascha,

Comments below.

Sascha Theves wrote:
Hi Ed,

thanks for the quick answer! We think that it is caused by a concurrency
problem too. But we can not imagine where the problem exactly comes from.
Could you show me some insights of the EMF code where the concurrency
problem could occur? I think in our case it is somehow caused when we read
our model in parallel. Some of our containment references are objects that
are persisted in its own resource. Iterating over these containment
references causes EMF to resolve proxies. When that happens new resources
must be added to the resource set. But that is done internally by EMF and
not in our code. That would mean we can not read our model at the same time
in two different threads. Am I right?

Yes, resolving proxies on multiple threads at the same time will cause
issues. This is one of the things the transaction framework helps with,
i.e., you must create a read transaction. Or you might just specialize your
ResourceSetImpl to add a synchronize to getResource to serialize access.

Thanks for your help!

Cheers

Sascha


"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:hstrsu$cdp$1@build.eclipse.org...

Sascha,

ResourceSets aren't thread safe so that's a likely source of the problem
you describe. I've seen, for example, many problems reported from WTP
about null in the list of adapters and those were definitely caused by
adding an adapter on two threads at the same time.


Sascha Theves wrote:

Hi all,

we have an EMF model that is persisted in many resources on filesystem.
All these resources are contained in one ResourceSet as EMF resource. The
strange thing is that we get sometimes null-Entries in the resource list
of the resource set. The problem is that we do not really know where the
null entry comes from. We have seen that EMF perfroms Null-Checks before
inserting a resource in the resource set, so it should not be possible to
have null entries in the resource set. Has anybody an idea where these
null entries are coming from? Or does anybody know how to insert a null
resource in the resource set with bypassing the null checks from EMF?

Cheers

Sascha
Re: null as Resource in ResourceSet [message #619631 is a reply to message #534575] Wed, 19 May 2010 15:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26289
Registered: July 2009
Senior Member
Tim,

I don't see any further questions here. Just to be clear: don't expect
anything in EMF to change to provide thread safety. Thread safety needs
to be achieved by a sound threading policy in the application as a
whole, not by judicious sprinklings of synchronized calls; that approach
just interferes with the high-level policy and leads to unavoidable
deadlocks.


Tim Baumgartner wrote:
> Hi Ed,
>
> I wrote a test case for this (see below). It passes for Resources, but it
> really fails if I change it to adapters, just like you told.
>
> Regards
> Tim
>
>
> public class NullResourceTest extends TestCase
> {
> private ResourceSet set;
>
> private class ResourceThread extends Thread
> {
> private Resource resource;
>
> public ResourceThread()
> {
> resource = new XMIResourceImpl();
> }
>
> @Override
> public void run()
> {
> if (set.getResources().contains(resource))
> {
> set.getResources().remove(resource);
> }
> else
> {
> set.getResources().add(resource);
> }
> }
> }
>
> @Override
> protected void setUp() throws Exception
> {
> set = new ResourceSetImpl();
> }
>
> public void test() throws Exception
> {
> for (int i = 0; i < 10; i++)
> {
> new ResourceThread().start();
> }
> long time = System.currentTimeMillis();
> while (System.currentTimeMillis() < time + 10000)
> {
> if (set.getResources().contains(null))
> {
> fail("Null in ResourceSet");
> }
> }
> }
> }
>
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hsu2g3$muh$1@build.eclipse.org...
> Sascha,
>
> Comments below.
>
> Sascha Theves wrote:
> Hi Ed,
>
> thanks for the quick answer! We think that it is caused by a concurrency
> problem too. But we can not imagine where the problem exactly comes from.
> Could you show me some insights of the EMF code where the concurrency
> problem could occur? I think in our case it is somehow caused when we read
> our model in parallel. Some of our containment references are objects that
> are persisted in its own resource. Iterating over these containment
> references causes EMF to resolve proxies. When that happens new resources
> must be added to the resource set. But that is done internally by EMF and
> not in our code. That would mean we can not read our model at the same time
> in two different threads. Am I right?
>
> Yes, resolving proxies on multiple threads at the same time will cause
> issues. This is one of the things the transaction framework helps with,
> i.e., you must create a read transaction. Or you might just specialize your
> ResourceSetImpl to add a synchronize to getResource to serialize access.
>
> Thanks for your help!
>
> Cheers
>
> Sascha
>
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:hstrsu$cdp$1@build.eclipse.org...
>
> Sascha,
>
> ResourceSets aren't thread safe so that's a likely source of the problem
> you describe. I've seen, for example, many problems reported from WTP
> about null in the list of adapters and those were definitely caused by
> adding an adapter on two threads at the same time.
>
>
> Sascha Theves wrote:
>
> Hi all,
>
> we have an EMF model that is persisted in many resources on filesystem.
> All these resources are contained in one ResourceSet as EMF resource. The
> strange thing is that we get sometimes null-Entries in the resource list
> of the resource set. The problem is that we do not really know where the
> null entry comes from. We have seen that EMF perfroms Null-Checks before
> inserting a resource in the resource set, so it should not be possible to
> have null entries in the resource set. Has anybody an idea where these
> null entries are coming from? Or does anybody know how to insert a null
> resource in the resource set with bypassing the null checks from EMF?
>
> Cheers
>
> Sascha
>
>
>
>
>
>
>
>
>
Previous Topic:null as Resource in ResourceSet
Next Topic:Re: Graphiti Creation Review Successful
Goto Forum:
  


Current Time: Mon Dec 22 12:49:26 GMT 2014

Powered by FUDForum. Page generated in 0.02114 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software