I am working with eclipselink*(version 4.0.4)* L2 cache optimization. For that I have implemented static weaving as Wildfly*(version 32.0.1.Final)*/Jboss server doesn't support dynamic weaving (as mentioned here : https://eclipse.dev/eclipselink/documentation/4.0/solutions/solutions.html#how-to-disable-or-enable-weaving-in-a-jakarta-ee-environment) so that Lazy loading can be implemented for JPAs. I am using a external Database configured using datasource subsystem of wildfly with min-pool-size : 40 and max-pool-size : 400, and blocking-timeout-millis : 800 ms.
I have multiple JPAs which have multiple nested bidirectional @oneToMany and @oneToOne mapping. I have made every reverse directional @manyToOne mapping as LAZY loaded and confirmed that the LAZY loaded relations are not being loaded unnecessarily. I have only kept those relation as EAGER which are absolutely use together.
My code uses [read only] connection outside of transactional context and the only [default] connections are used inside the transactional context and at the end of the code I use executor service to run different processes for seperate processes. In this seperate proccesses. My only interation with the persistence context is using @local Dao interface whose @Stateless @EJB DaoImpl bean contains these :
@PersistenceContext(unitName = "contextName")
EntityManager em;
The executor service threads also uses the Dao interface by doing a Bean lookup for using some methods DaoImpl which are only read operations.
Now when I proccess single request and check for my request throughput it has significantly improved. But when I throw mutiple request at some throughput my connection pool is getting exhausted while with the same code without any changes my connection pool is able to hold the throughput.
Why is this happening? I have searched on web and was not able to find any definite solution. I am very new to stackoverflow, please do tell me if I need to provide anything else. Help is much appreciated.
I have analysed that I have a JPA1 with some @oneToOne and @oneToMany bidirectional mappings with LAZY loading and later used with the reverse @oneToOne and @manyToOne mappings are LAZY loaded and never used and thus not loaded. In the end of the transactional context I use a Named Query to find all the JPA1 entries related to a some "parentID" attribute. These kind of queries don't hit L2 cache and thus always go to DB. After that the executor service calls some threads and these threads use these JPA1 entry's LAZY loaded relations of the earlier loaded entities. Eclipselink supports the loading of LAZY relationships even if the entity manager closes. I suspect that these are the cause of DB exhaustion but even if I make these entities EAGER loaded the DB exhaustion probelem still remains.
I have also tried using @JoinFetch(JoinFetchType.OUTER) and @JoinFetch(JoinFetchType.INNER) but the connection problem still remains but the number of connection getting used are reduced.
I have tried counting the number of connection used before the change and after the change but the connections are used less in case where I have done the LAZY loading and static weaving change. Then why was the connection pool exhausted in the case where less connections are being used?
Below are my datasource statistics from widlfy admin console :
Datasource Statistics without the weaving and lazyloading changes
Datasource Statistics with the weaving and lazyloading changes