Java – connection pool for dynamic database connections

The problem setting is based on a web service (spring / Java, tomcat7 and MySQL). Each user obtains its own database, so each request needs its own connection Because all databases are created dynamically at runtime, static configuration is not an option before startup

To optimize database connection usage, the implementation of database connection pool will be very good, right?

Using Java / spring: how to create a connection pool for a dynamic database? My lack of clean choice here is a little shocking!

Problem: Tomcat's connection pool (as far as I know, c3p0 also regards each new datasource instance as a new connection pool – > stack reference

>Is it a good idea to use a generic MySQL connection to create a static data source (without specifying the database on the connection), and use the connection pool with this data source and the applicable SQL statements? Stack reference > how to develop a data source pool based on persistent database? Any performance experience? Any suggestions? Does any library do this? > Or whether you can dynamically manipulate its context from Java XML to dynamically create a Tomcat JNDI database to solve the datasource problem of Tomcat? > I can't believe there is no simpler / simpler solution Grails / Hibernate is struggling with this, Java / JDBC is struggling with this,... Such a rare use case is to separate user data by dynamically creating a user specific database? If so, what is the better setting?

edit

>Another option is @ m.deinum. It is recommended to use a single configured data source and dynamically replace it with the correct connection – > m.deinum blog and stack reference How do I use the same connection pool as above?

Solution

First of all, I'm sorry for my English. I'm improving every day

According to my experience, I have a similar situation, which is solved by spring framework Let me explain how you solved the problem

>Create a spring configuration file with the following characteristics: a) resource loader: This is responsible for loading properties from the configuration file or database, which will be used to establish database connection b) Pool database configuration parameterized with the attributes to load. > Create a locator class: in this class, you need a HashMap > use spring's multi context function: the idea is to assign a code to each connection you establish, and later use spring to load the connection into the application context, and then in the locator class, put the mapping in the context and use it as a frequent as needed

I think you follow these steps to create dynamic pools or database connections as needed

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>