Re: ArrayIndexOutOfBounds exception on un-synchronized model modifications?

2017-04-11 Thread A. Soroka
Yes, you will want to exercise some control over concurrency here:

https://jena.apache.org/documentation/notes/concurrency-howto.html

---
A. Soroka
The University of Virginia Library

> On Apr 11, 2017, at 1:16 PM, Joshua TAYLOR  wrote:
> 
> I expect the answer to my question is simply "make sure model access
> is synchronized", but just in case, I'm wondering whether this is
> expected behavior.  Here's some code that modifies a model from a
> bunch of different threads. This doesn't cause an error every time,
> but occasionally throws, as shown in the stacktrace following the
> code.
> 
> The class here is called OhDearTest, because I getting a
> `jena.shared.BrokenException oh dear, already have a slot for ...`
> earlier, which I'm still trying to reproduce. This code doesn't seem
> to trigger it. I've included a bit of that stacktrace at the very end.
> 
> ## Code
> 
> import org.apache.jena.rdf.model.Model;
> import org.apache.jena.rdf.model.ModelFactory;
> import org.apache.jena.rdf.model.Property;
> import org.apache.jena.rdf.model.Resource;
> 
> public class OhDearTest {
>  public static void main(String[] args) throws InterruptedException {
>int n = 1000;
>Model model = ModelFactory.createDefaultModel();
>Property p = model.createProperty("urn:ex:p");
>Thread[] thread = new Thread[n];
>for (int i = 0; i < n; i++) {
>  thread[i] = new Thread(() -> {
>Resource r = model.createResource();
>r.addLiteral(p, "value");
>  });
>  thread[i].start();
>}
>for (int i = 0; i < n; i++) {
>  thread[i].join();
>}
>  }
> }
> 
> ## Stacktrace
> 
> Exception in thread "Thread-300" Exception in thread "Thread-299"
> Exception in thread "Thread-304" Exception in thread "Thread-282"
> Exception in thread "Thread-324" Exception in thread "Thread-331"
> Exception in thread "Thread-328"
> java.lang.ArrayIndexOutOfBoundsException: 905
>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>at 
> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>at 
> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>at 
> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>at OhDearTest.lambda$0(OhDearTest.java:15)
>at java.lang.Thread.run(Thread.java:745)
> java.lang.ArrayIndexOutOfBoundsException: 789
>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>at 
> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>at 
> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>at 
> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>at OhDearTest.lambda$0(OhDearTest.java:15)
>at java.lang.Thread.run(Thread.java:745)
> java.lang.ArrayIndexOutOfBoundsException: 827
>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>at 
> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>at 
> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>at 
> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>at OhDearTest.lambda$0(OhDearTest.java:15)
>at java.lang.Thread.run(Thread.java:745)
> java.lang.ArrayIndexOutOfBoundsException: 1061
>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>at org.apache.jena.mem.HashedBunchMap.put(HashedBunchMap.java:66)
>at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:51)
>at 
> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:60)
>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>at 
> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>at OhDearTest.lambda$0(OhDearTest.java:15)
>at java.lang.Thread.run(Thread.java:745)
> java.lang.ArrayIndexOutOfBoundsException: 918
>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.j

Re: ArrayIndexOutOfBounds exception on un-synchronized model modifications?

2017-04-14 Thread Joshua TAYLOR
Thanks, this is exactly what I needed. I've used it in the past, but
have been "away" long enough that I'd forgotten about it.

On Tue, Apr 11, 2017 at 4:23 PM, A. Soroka  wrote:
> Yes, you will want to exercise some control over concurrency here:
>
> https://jena.apache.org/documentation/notes/concurrency-howto.html
>
> ---
> A. Soroka
> The University of Virginia Library
>
>> On Apr 11, 2017, at 1:16 PM, Joshua TAYLOR  wrote:
>>
>> I expect the answer to my question is simply "make sure model access
>> is synchronized", but just in case, I'm wondering whether this is
>> expected behavior.  Here's some code that modifies a model from a
>> bunch of different threads. This doesn't cause an error every time,
>> but occasionally throws, as shown in the stacktrace following the
>> code.
>>
>> The class here is called OhDearTest, because I getting a
>> `jena.shared.BrokenException oh dear, already have a slot for ...`
>> earlier, which I'm still trying to reproduce. This code doesn't seem
>> to trigger it. I've included a bit of that stacktrace at the very end.
>>
>> ## Code
>>
>> import org.apache.jena.rdf.model.Model;
>> import org.apache.jena.rdf.model.ModelFactory;
>> import org.apache.jena.rdf.model.Property;
>> import org.apache.jena.rdf.model.Resource;
>>
>> public class OhDearTest {
>>  public static void main(String[] args) throws InterruptedException {
>>int n = 1000;
>>Model model = ModelFactory.createDefaultModel();
>>Property p = model.createProperty("urn:ex:p");
>>Thread[] thread = new Thread[n];
>>for (int i = 0; i < n; i++) {
>>  thread[i] = new Thread(() -> {
>>Resource r = model.createResource();
>>r.addLiteral(p, "value");
>>  });
>>  thread[i].start();
>>}
>>for (int i = 0; i < n; i++) {
>>  thread[i].join();
>>}
>>  }
>> }
>>
>> ## Stacktrace
>>
>> Exception in thread "Thread-300" Exception in thread "Thread-299"
>> Exception in thread "Thread-304" Exception in thread "Thread-282"
>> Exception in thread "Thread-324" Exception in thread "Thread-331"
>> Exception in thread "Thread-328"
>> java.lang.ArrayIndexOutOfBoundsException: 905
>>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>>at 
>> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>>at 
>> org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>>at 
>> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>>at 
>> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>>at OhDearTest.lambda$0(OhDearTest.java:15)
>>at java.lang.Thread.run(Thread.java:745)
>> java.lang.ArrayIndexOutOfBoundsException: 789
>>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>>at 
>> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>>at 
>> org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>>at 
>> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>>at 
>> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>>at OhDearTest.lambda$0(OhDearTest.java:15)
>>at java.lang.Thread.run(Thread.java:745)
>> java.lang.ArrayIndexOutOfBoundsException: 827
>>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>>at 
>> org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
>>at 
>> org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
>>at 
>> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
>>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
>>at 
>> org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
>>at OhDearTest.lambda$0(OhDearTest.java:15)
>>at java.lang.Thread.run(Thread.java:745)
>> java.lang.ArrayIndexOutOfBoundsException: 1061
>>at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
>>at org.apache.jena.mem.HashedBunchMap.put(HashedBunchMap.java:66)
>>at 
>> org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:51)
>>at 
>> org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:60)
>>at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
>>at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
>>at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java

Re: ArrayIndexOutOfBounds exception on un-synchronized model modifications?

2017-04-14 Thread Andy Seaborne

Or transactions.

DatasetFactory.createTxnMem()

And "Txn" if you like the java8 Style.

jena.apache.org/documentation/txn/

Andy

On 14/04/17 12:11, Joshua TAYLOR wrote:

Thanks, this is exactly what I needed. I've used it in the past, but
have been "away" long enough that I'd forgotten about it.

On Tue, Apr 11, 2017 at 4:23 PM, A. Soroka  wrote:

Yes, you will want to exercise some control over concurrency here:

https://jena.apache.org/documentation/notes/concurrency-howto.html

---
A. Soroka
The University of Virginia Library


On Apr 11, 2017, at 1:16 PM, Joshua TAYLOR  wrote:

I expect the answer to my question is simply "make sure model access
is synchronized", but just in case, I'm wondering whether this is
expected behavior.  Here's some code that modifies a model from a
bunch of different threads. This doesn't cause an error every time,
but occasionally throws, as shown in the stacktrace following the
code.

The class here is called OhDearTest, because I getting a
`jena.shared.BrokenException oh dear, already have a slot for ...`
earlier, which I'm still trying to reproduce. This code doesn't seem
to trigger it. I've included a bit of that stacktrace at the very end.

## Code

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;

public class OhDearTest {
 public static void main(String[] args) throws InterruptedException {
   int n = 1000;
   Model model = ModelFactory.createDefaultModel();
   Property p = model.createProperty("urn:ex:p");
   Thread[] thread = new Thread[n];
   for (int i = 0; i < n; i++) {
 thread[i] = new Thread(() -> {
   Resource r = model.createResource();
   r.addLiteral(p, "value");
 });
 thread[i].start();
   }
   for (int i = 0; i < n; i++) {
 thread[i].join();
   }
 }
}

## Stacktrace

Exception in thread "Thread-300" Exception in thread "Thread-299"
Exception in thread "Thread-304" Exception in thread "Thread-282"
Exception in thread "Thread-324" Exception in thread "Thread-331"
Exception in thread "Thread-328"
java.lang.ArrayIndexOutOfBoundsException: 905
   at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
   at org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
   at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
   at org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
   at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
   at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
   at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
   at 
org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
   at OhDearTest.lambda$0(OhDearTest.java:15)
   at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 789
   at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
   at org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
   at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
   at org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
   at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
   at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
   at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
   at 
org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
   at OhDearTest.lambda$0(OhDearTest.java:15)
   at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 827
   at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
   at org.apache.jena.mem.HashedTripleBunch.contains(HashedTripleBunch.java:40)
   at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:52)
   at org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:63)
   at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
   at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
   at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
   at 
org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
   at OhDearTest.lambda$0(OhDearTest.java:15)
   at java.lang.Thread.run(Thread.java:745)
java.lang.ArrayIndexOutOfBoundsException: 1061
   at org.apache.jena.mem.HashCommon.findSlot(HashCommon.java:164)
   at org.apache.jena.mem.HashedBunchMap.put(HashedBunchMap.java:66)
   at org.apache.jena.mem.NodeToTriplesMapMem.add(NodeToTriplesMapMem.java:51)
   at org.apache.jena.mem.GraphTripleStoreBase.add(GraphTripleStoreBase.java:60)
   at org.apache.jena.mem.GraphMem.performAdd(GraphMem.java:37)
   at org.apache.jena.graph.impl.GraphBase.add(GraphBase.java:181)
   at org.apache.jena.rdf.model.impl.ModelCom.add(ModelCom.java:1191)
   at 
org.apache.jena.rdf.model.impl.ResourceImpl.addLiteral(ResourceImpl.java:285)
   at OhDearTest.lambda$0(OhDearTest.java:15)