0

I have a multi-module JavaEE project where several beans carry methods

findByColumn(String value)

I'd like to factorize all these different findBy* methods in a single super class.

I know the risk of such design is that I could potentially create a bottleneck for my application when it comes to finding something in a given persistence unit.

However, I noticed that if I made this method asynchronous, then it could solve my bottleneck problem since the calls wouldn't be blocking.

I was wondering if it's possible to make the EntityManager transactions asynchronous, i.e., if the EntityManager is thread-safe, and if my solution would really solve the bottleneck problem.

Maxime Flament
  • 721
  • 1
  • 7
  • 24
  • Normally, each thread (typically handling a HTTP request) will get it's own entity manager and database connection. Perhaps you should show more code demonstrating how you get your entity manager instance – Steve C Apr 14 '18 at 14:52
  • The entitytmanager instance is created by my container TomEE, and injected into the beans that need it. – Maxime Flament Apr 14 '18 at 14:53
  • Then you're worrying about nothing. Any bottlenecks will be based upon your database schema and the queries you perform. Your code will block at the database connection and no amount of asynchronicity will fix that. – Steve C Apr 14 '18 at 14:57
  • I was talking about the bottleneck that can occur if multiple beans call the same findBy method. – Maxime Flament Apr 14 '18 at 17:10
  • Show your code please, otherwise you're forcing us to guess what you're talking about. – Steve C Apr 15 '18 at 00:03
  • I don't have code yet, but I'll try to provide you a minimal example with what I'm trying to do. – Maxime Flament Apr 15 '18 at 11:15

0 Answers0