Home > Mobile >  Multiple ORACLE DB connections created while running 1 spring boot app
Multiple ORACLE DB connections created while running 1 spring boot app

Time:09-27

I am trying to understand the correlation between Database connections and spring boot app. My spring boot app is connecting to one schema and I am running 4 such spring boot apps on my system. Each app is connecting to a different schema. The problem is that these 4 apps are acquiring 50 oracle db connections, but when I close all apps and open DB through oracle sql developer only one connection is acquired.

CodePudding user response:

I don't have enough rep to post this as a comment.

By default Spring Boot uses HikariCP as a connection pooling framework. Some good information can be found at Baeldung, which I recommend using as it covers lots Spring Boot functionality and is almost always up to date.

https://www.baeldung.com/hikaricp

Spring-boot specific information:

https://www.baeldung.com/spring-boot-hikari

While 10 connections are not at all required, you can 'play' around with how much is best (or most optimum) for your app and set it as best fits your design. Usually this will be done by optimizing this as the need arises in your application. 10 is what spring/hikari identifies as a good starting point for most projects.

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#data.sql.datasource.connection-pool

Since I had to post this as an answer I'll go a little more in depth in your actual question:

If we think of a connection to a database without a pool we can think of:

  1. The application requests the driver to open a connection to your database
  2. A socket is opened between your application and the database
  3. You are authenticated to the database
  4. Your query runs and the connection is closed

This is fine in a small application without many requests going through, but hopefully you can see the issue here as we scale and get more users. Removing the first 3 steps can make a huge difference.

It should also be noted that while your database holds 3 connections, the connections will be idle and not generating much (if any) load on your database.

  • Related