Reputation: 31
I have a use case where i need to run my stored proc in parallel thread in neo4j. I have written the stored proc and included it in the neo4j plugins. But while i am running the stored proc i am getting below error:
2016-06-24 05:45:54.683+0000 INFO Remote interface available at http://localhost:7474/
java.lang.UnsupportedOperationException: Creating new transactions and/or spawning threads are not supported operations in store procedures.
at org.neo4j.kernel.impl.proc.ProcedureGDBFacadeSPI.assertSameThread(ProcedureGDBFacadeSPI.java:108)
at org.neo4j.kernel.impl.proc.ProcedureGDBFacadeSPI.isInOpenTransaction(ProcedureGDBFacadeSPI.java:124)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTransaction(GraphDatabaseFacade.java:335)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacade.beginTx(GraphDatabaseFacade.java:330)
at example.SearchTask.call(SearchTask.java:33)
at example.SearchTask.call(SearchTask.java:17)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I have understood that in neo4j customized stored proc can not run in parallel threads.
But i am looking is there any way where i can run it in parallel.
Upvotes: 1
Views: 379
Reputation: 39925
When using
@Context
GraphDatabaseService graphDb
you'll get a wrapped GDS that does not allow for explicit transaction/thread management. If you need to do that in a procedure you have to use non-public API like this:
@Context
GraphDatabaseAPI graphDb
This one is not wrapped and therefore allows you to do all the nasty things. For a real world example see https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/master/src/main/java/apoc/periodic/Periodic.java#L26
Upvotes: 5