Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-09-2020 06:15 AM
Hello,
I have a SpringBoot application where I'm using the following dependency:
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver-spring-boot-starter</artifactId>
<version>1.7.5</version>
</dependency>
My application needs to support high level of concurrent access for reads and writes.
At the moment, each time I want to interact with the database I'm creating a new session and then executing multiple transaction on that session scope. In the end, the session is closed. I'm doing it like this:
try (Session session = driver.session()) {
return session.readTransaction(tx -> {
String query = ...
StatementResult result = tx.run(query);
...
});
}
However, I was wondering if this the best way to do it, or if I should avoid the creation of a session everytime an interaction with the database is done. Would not be better to create a session when the application starts reuse that same session over and over? Or have 1 session for reads and another for writes?
I read in the documentation that sessions are not thread-safe. Not even for reads?
Thanks for your help.
01-09-2020 06:25 AM
The most common way I've seen is to have one session for reads and another for writes.
01-09-2020 07:03 AM
But in that case does it behave well if there are concurrent read or write requests?
01-09-2020 07:13 AM
I guess what I mean to say is that unless you're using it without some sort of streaming tool or something like reddis, etc. The you're going to be calling functions that preform their own read and write actions and their own individual sessions. There's no leaving a session open otherwise, at least not in my experience. Some other folks on here may/hopefully have a more complete answer.
All the sessions of the conference are now available online