cyberborean/rdfbeans

Thread-safe RDFBeanManager

cyberborean opened this issue · 6 comments

Currently, RDFBeanManager is instantiated on a single pre-opened RepositoryConnection that cannot be shared over multiple threads by design. To enable concurrent access to a RDFBeans repository, one has to create multiple RDFBeanManager instances with connections obtained for each thread separately. This is an annoying limitation that makes development of multi-thread RDFBeans applications more complex and error-prone. This also interfering with the role of RDFBeanManager as a central application data model.

The idea is to move the per-thread RepositoryConnection management into RDFBeanManager implementation:

  • RDFBeanManager is instantiated on a Repository object instead of RepositoryConnection
  • RDFBeanManager is responsible for opening new RepositoryConnections. New connections are created as needed internally and pooled in a thread-local manner: an isolated RepositoryConnection instance is obtained by each thread to guarantee thread-safe model updates.
  • RepositoryConnection for the current thread is exposed publicly through getRepositoryConnection() method for external transaction management.
  • RDFBeanManager has an explicit close() method for closing all pooled connections.

RepositoryConnection for the current thread is exposed publicly through getRepositoryConnection() method for external transaction management.

This implies that the user code may also close the current connection. Connection pool implementation should handle this situation (check and re-open connections if necessary).

Hi! Sorry to bother you but I'm evaluating this package. To have multi-thread support would make it much more usable for me.
Are you still working on this task? Do you need help in testing?

Hi!

This is basically completed in the "feature-24" branch, testing is very appreciated!

Please check the code of RDFBeanManager to learn about API changes. Specifically: the constructor now takes a Repository as a parameter (not RepositoryConnection). RDFBeanManager creates new connections internally in a thread-local manner.

Thanks!

Great, thanks for your reply!
I will give it a try :)

I'll update the docs and merge this to the develop branch this week.