java - Multithreading in Titan throws exception -


i creating vertices in titan multiple threads. here's code

trying connect titan, specifying schema , adding vertices.

g = titanfactory.open("/conf/titan-cassandra.properties"); titanmanagement mgmt = g.getmanagementsystem(); final propertykey userid = mgmt.makepropertykey("userid").datatype(integer.class).make(); titangraphindex namei = mgmt.buildindex("userid",vertex.class).addkey(userid).unique().buildcompositeindex(); mgmt.setconsistency(namei, consistencymodifier.lock); mgmt.commit(); 

then i'm calling function add vertex

multiple threads accessing function add vertex takes input parameter - randomly generated unique numbers (entitypk)

tx1 = g.newtransaction(); vertex user_ver = tx1.addvertexwithlabel("user"); user_ver.setproperty("userid",entitypk); //adding other properties vertex tx1.commit();` 

i read exception thrown because of not specifying lock. after specifying lock, exception thrown.

com.thinkaurelius.titan.core.titanexception: not commit transaction due exception during persistence

if code:

tx1 = g.newtransaction(); vertex user_ver = tx1.addvertexwithlabel("user"); user_ver.setproperty("userid",entitypk); //adding other properties vertex tx1.commit(); 

is inside of addvertex function , multiple threads calling addvertex, don't think you're using newtransaction quite right. creates referred "threaded transaction". threaded transaction 1 multiple threads act on same transaction. in usage, each thread creating own different transaction. given you've described, correct approach make addvertex be:

vertex user_ver = g.addvertexwithlabel("user"); user_ver.setproperty("userid",entitypk); //adding other properties vertex g.commit(); 

i consider dropping locking (unless need it).


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -