}
}
//@Test
public void test() {
final StoreConnection storeConnection =
StoreConnection.make(Location.mem());
//ExecutorService executor = Executors.newCachedThreadPool() ; // Not seen blocking.
// 4 blocks maybe 1 in 4 times
// 8 blocks (quad core) 2 in 3 times.
ExecutorService executor = Executors.newFixedThreadPool(8) ;
final AtomicInteger nbQuadruplesAdded = new AtomicInteger();
final CountDownLatch doneSignal =
new CountDownLatch(CONCURRENT_RANDOM_OPERATIONS);
for (int i = 0; i < CONCURRENT_RANDOM_OPERATIONS; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
if (numberGenerator.nextInt(2) == 0) {
DatasetGraphTxn txnGraph =
storeConnection.begin(ReadWrite.WRITE);
txnGraph.add(new Quad(
Node.createURI("http://openjena.org/"
+ numberGenerator.nextInt()),
Node.createURI("http://openjena.org/"
+ numberGenerator.nextInt()),
Node.createURI("http://openjena.org/"
+ numberGenerator.nextInt()),
Node.createURI("http://openjena.org/"
+ numberGenerator.nextInt())));
txnGraph.commit();
txnGraph.end();
nbQuadruplesAdded.incrementAndGet();
} else {
DatasetGraphTxn txnGraph =
storeConnection.begin(ReadWrite.READ);
txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
//Iterator<Quad> iter = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
//Iter.count(iter) ; // Consume
txnGraph.end();
}
} finally {
doneSignal.countDown();
}
}
});
}
// shutdown is orderly so sync'ing up before the shutdown is nice but not needed.
try {
doneSignal.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
executor.shutdown();
}
DatasetGraphTxn txnGraph =
storeConnection.begin(ReadWrite.READ);
Iterator<Quad> result = txnGraph.find(
Node.ANY, Node.ANY, Node.ANY, Node.ANY);
long count = 0;
while (result.hasNext()) {
result.next();
count++;
}
txnGraph.end();
StoreConnection.release(storeConnection.getLocation());
//System.out.println() ;
System.out.println("FINISHED") ;
// // This is unsafe - the quad adds may generate duplicates (ity's unlikly 4 random number reoccur but it's possible).