简体   繁体   中英

ArangoDB java-driver reuse of objects

In many of the examples using the java arangoDB driver , they use method chaining

arangoDB.db("myDatabase").createCollection("myCollection", null);

or

arangoDB.db("myDatabase").collection("myCollection").insertDocument(myObject);

Are there any drawbacks with re-using objects?

ArangoDatabase db = arangoDB.db("myDatabase");
...
db.createCollection("myCollection", null);
ArangoCollection coll = db.collection("myCollection");
...
coll.insertDocument(myObject);

I am not sure if chaining approach is preferred or just for simplicity (fewer lines for an example).

  • Is there much of a performance benefit to reuse? Less object creation overhead...
  • Are connection, database and collection objects thread safe? ie after getting a database can the object be shared between multiple threads?

Yes, you can reuse instances of ArangoDatabase, ArangoCollection, ArangoGraph, ArangoVertexCollection, ArangoEdgeCollection.

  • Yes, there is a small performance benefit through less object creation.
  • Yes, all of them are thread-safe. You can share them between threads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM