Hi Steve,
With OrientDB each thread must have own graph instance, so try this:

public class ConcurrencyTest {
    private OrientGraphFactory factory;
    @Before
    public void setup() {
        factory = new OrientGraphFactory("memory:test");
    }
    @Test
    public void testConcurrentAccess() {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 1; i++) {
            Runnable worker = new MyThread(factory);
            executor.execute(worker);
        }
        executor.shutdown();
        while (!executor.isTerminated()) {
        }
    }
    public static class MyThread implements Runnable {
        private TransactionalGraph graph;
        public MyThread(OrientGraphFactory factory) {
            this.graph = factory.getTx();
        }
        @Override
        public void run() {
            graph.getFeatures();
            Iterable<Vertex> vertices = graph.getVertices();
            long count = 0;
            for (Vertex v : vertices) {
                count++;
            }
            System.out.println("Found " + count + " vertices");
        }
    }
}

Lvc@



On 6 May 2014 17:09, <[email protected]> wrote:

> I'm starting to use the Blueprints API (2.5.0) with OrientDB backend
> (1.7-rc2). No surprises until I try to access a graph from a Runnable, then
> I get:
>
> Exception in thread "pool-1-thread-1"
> com.orientechnologies.orient.core.exception.ODatabaseException: Cannot open
> database
>  at
> com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:326)
>  at
> com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:54)
>  at
> com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.openOrCreate(OrientBaseGraph.java:878)
>  at
> com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getContext(OrientBaseGraph.java:854)
>  at
> com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getVerticesOfClass(OrientBaseGraph.java:469)
>  at
> com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getVertices(OrientBaseGraph.java:457)
>  at mypackage.ConcurrencyTest$MyThread.run(ConcurrencyTest.java:49)
>  at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>  at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>  at java.lang.Thread.run(Thread.java:744)
> Caused by: java.lang.NullPointerException
>  at
> com.orientechnologies.orient.core.security.OSecurityManager.digest2String(OSecurityManager.java:81)
>  at
> com.orientechnologies.orient.core.security.OSecurityManager.check(OSecurityManager.java:61)
>  at
> com.orientechnologies.orient.core.metadata.security.OUser.checkPassword(OUser.java:164)
>  at
> com.orientechnologies.orient.core.metadata.security.OSecurityShared.authenticate(OSecurityShared.java:164)
>  at
> com.orientechnologies.orient.core.metadata.security.OSecurityProxy.authenticate(OSecurityProxy.java:83)
>  at
> com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:291)
>  ... 9 more
>
>   I reduced what I was trying to do as much as I could, resulting in this
> test case:
> package mypackage;
> import com.tinkerpop.blueprints.*;
> import com.tinkerpop.blueprints.impls.neo4j2.*;
> import com.tinkerpop.blueprints.impls.orient.*;
> import org.junit.*;
> import org.neo4j.graphdb.*;
> import org.neo4j.test.*;
> import java.util.concurrent.*;
> public class ConcurrencyTest {
>     private TransactionalGraph graph;
>     @Before
>     public void setup() {
>         OrientGraphFactory factory = new OrientGraphFactory("memory:test");
>         graph = factory.getTx();
>     }
>     @Test
>     public void testConcurrentAccess() {
>         ExecutorService executor = Executors.newFixedThreadPool(5);
>         for (int i = 0; i < 1; i++) {
>             Runnable worker = new MyThread(graph);
>             executor.execute(worker);
>         }
>         executor.shutdown();
>         while (!executor.isTerminated()) {
>         }
>     }
>     public static class MyThread implements Runnable {
>         private TransactionalGraph graph;
>         public MyThread(TransactionalGraph graph) {
>             this.graph = graph;
>         }
>         @Override
>         public void run() {
>             graph.getFeatures();
>             Iterable<Vertex> vertices = graph.getVertices();
>             long count = 0;
>             for (Vertex v : vertices) {
>                 count++;
>             }
>             System.out.println("Found " + count + " vertices");
>         }
>     }
> }
> What am I missing? For what it's worth, I get exactly the same stack trace
> if I use OrientGraphFactory("plocal:C:/temp/graph/db", "admin", "admin"),
> and this trivial test works if I use a Neo4j2 graph backend.
>
> Regards,
> Steve
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "OrientDB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to