简体   繁体   中英

updating the data source while using connection pooling

I am running an application that uses a connection pooling in order to manage data fetching from the data base. For the connection pooling i am using HikariCP.

while the first application is running there is another application that updates the data base. Does the data source that was created for the connection pooling being updated automatically as well? If not, how can i do it? should i create a new connection pool every time the database updates?

For example: The database had a record of a student with some grade. A data source was created for the connection pool. Than the grade of the student was changed. How do i update the data source?

Any help would be appreciated. Thank you.

Hope this clears up your confusion.

Most applications only need a thread to have access to a JDBC connection when they are actively processing a transaction, which often takes only milliseconds to complete. When not processing a transaction, the connection sits idle. Connection pooling enables the idle connection to be used by some other thread to do useful work.

In practice, when a thread needs to do work against a MySQL or other database with JDBC, it requests a connection from the pool. When the thread is finished using the connection, it returns it to the pool, so that it can be used by any other threads.

Regardless of whether you use connection pooling or not, updates to the database by other applications will happen normally and each time you query the database you will see the fresh data. There isn't a need for you to 'update the connection pool'

This diagram might help you understand what's actually happening:

数据库服务器架构图

What Java refers to as a "DataSource" is an abstract concept representing the location of the data, not the data itself. You can create multiple connections to a data source, but you will only have one single copy of that data, controlled by the database server.

If you update the data from one application, you're sending a message via the connection to the database server to change the data held in the data store. Committed changes are immediately visible to any other application because they're all using the same database (ie, the same physical data store).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM