My current production setup requires me to share Oracle database connection pools between multiple Spring Boot apps where each app runs via an embedded Tomcat instance.
What options do I have to share the database connection pool among these Spring Boot apps?
Is JNDI an option? If so, could someone explain how storing the connection pool details in say LDAP accessed via JNDI works?
Related
We are using spring boot, apache camel and multiple datasources.
spring boot version: 1.5.9 release
primary database: postgres
Secondary database:oracle
We have deployed spring boot jar in linux server.
Datasource properties for postgres is
x.datasource.url=
x.datasource.username=
x.datasource.password=
x.data.jpa.repositories.enabled=true
datasource properties for oracle
y.datasource.url=
y.datasource.username=
y.datasource.password=
y.data.jpa.repositories.enabled=true
when application keeps ideal and After some times we are trying first request failed and getting error jdbc connection failed but it is working in second request without restarting.
please let me know how to keep database active.
You can use hikari connection pool. Refer to this on how to implement. You can configure no. of connections you want to keep with db
I am working in modernizing an existing REST services and moving from OnPrem to AWS.
The legacy application
deployed in a OnPrem Liberty Server
MS SQL server DB was used.
Spring/Hibernate was the core technologies.
New Application Details :
Spring Boot deployed in the AWS environment in a docker container
Server-Tomcat embedded with the Spring boot.
Database is the existing MS Sql server and it is located OnPrem
Some queries which were earlier took less that 500ms to execute is now taking upto 2000ms. The queries,logic and other code related thigs are same between the legacy and the new application. We are not able to find why the queries are taking more time in this.
In the legacy application we had used the server.xml to configure the data source and in the new application we have configured the data source in the Spring boot application.properties . Below are the Datasource configurations:
Liberty Server datasource :
<dataSource id="Microsoft SQL Server JDBC Driver - DataSource - JVM3" jndiName="jdbc/xxx" containerAuthDataRef="yyy" statementCacheSize="50" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="MSSQLJDBCLib"/>
<properties.microsoft.sqlserver databaseName="dbName" serverName="servername.com" portNumber="9999" lockTimeout="2000" packetSize="4096" sendStringParametersAsUnicode="false" trustStorePassword="{xor}" beginTranForVendorAPIs="false" freeResourcesOnClose="false" jmsOnePhaseOptimization="false" reauthentication="false" preTestSQLString="SELECT 1" validateNewConnection="false" validateNewConnectionRetryInterval="3" errorDetectionModel="ExceptionMapping" nonTransactionalDataSource="false" name="Microsoft SQL Server JDBC Driver - DataSource - JVM3" enableMultithreadedAccessDetection="false" beginTranForResultSetScrollingAPIs="false" validateNewConnectionRetryCount="100" connectionSharing="1"/>
<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="300" maxPoolSize="30" minPoolSize="0" reapTime="240" purgePolicy="FailingConnectionOnly"/>
</dataSource>
Spring Boot Datasource :
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName
spring.datasource.hikari.maximumPoolSize=30
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=180000
What may be the other parameters which can impact the query performance between the old and the new application?
Note : The ping time between the AWS servers and the OnPrem db takes less than 2ms (very negligible).
The issue is fixed. All the queries which we made to the database were doing an Index scan instead of index seek. That is because we missed the sendStringParametersAsUnicode="false" parameter in the Connection JDBC url.
We changed the connection url to take the required parameters and the queries ran perfectly fine.
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName;packetSize=4096;sendStringParametersAsUnicode=false
I am a beginner working on a project in Netbeans and using Glasshfish, but I have to deploy on TOMCAT on Elastic BeanStalk. I don't know anything about tomcat. To connect to my database, I use Entity Classes and a named connection jdbc/whatever (I hear this is called a JDNI name) in my persistence.xml.
On the Glassfish server bundled with Netbeans, I added a Connection pool and a JDBC resource. This was done with a GUI. It was super simple. Create the JDBC connection pool after you stuffed the right driver in the right folder by pointing to the location of server/password/etc. Then point the jdbc resource at the pool.
Now I need to do this with TOMCAT and XML. I have no idea what I am doing...
How do I create a connection pool which all my applications can reach?
How do I then get JNDI? set up that persistence.xml can reference and make the magic db stuff happen?
How do I then set up a jdbc authentication realm based on this database?
It was magic in Glassfish is it was so GUI. But I don't have a GUI for TOMCAT.
I am using spring.
I'm using spring to connect to mysql currently.
I'm thinking of moving to simply servlets and drop spring as I don't need 99% of spring's functionality.
What do you suggest I use to get connection pooling functionality? Is there a mysql connection pool that is framework independent?
Even if you don't need 99% of Spring's features you can still use Spring JDBC which by itself is worthwhile. You don't need the whole Spring infrastructure to use it either - you can drop it in and use it by itself...no DI required. I have a coworker who is using Stripes as his app's framework but uses Spring JDBC for database access.
You don't say what your container is (e.g. Tomcat, JBoss, etc) but there are several container independent connection pools to choose from, such as DBCP, c3p0, BoneCP. If you're using Tomcat 7 it ships with a new connection pool called The Tomcat JDBC Connection Pool (I guess their marketing budget was cut :) ).
We just switched from DBCP to Tomcat's connection pool and it works great. We haven't run any benchmarks on it but haven't run into any issues yet either.
I recommend sticking with Spring JDBC even if you use another connection pool, just for the database connection/statement management, disconnected result set, and "free" prepared statements (Spring JDBC creates prepared statements under the hood for you).
I've tried researching how to use the DataSource method of connecting to a database but never could find out how. I know that a DataSource is first configured and registered to JNDI in an application that is separate from the user application, and all the user application will do is retrieve it using JNDI. What I don't understand is where the DataSource is configured. Is it automatically registered when I turn on MySQL, do I need to download another application to register it, or do I make a new class that will do that for me?
You usually have a Java EE app server like Glassfish, WebLogic, JBOSS, Tomcat, or Jetty have a JNDI provider that you should be using for the lookup.
Here's how you do it with Oracle.
Here's how you do it with MySQL.
The JDK 6 javadocs say that a basic DataSource can supply a connection if your driver has such an implementation. I would recommend looking at the Connector-J docs to see if you can do it without JNDI lookup services.