使用连接池更新数据源
updating the data source while using connection pooling
我是 运行 一个应用程序,它使用连接池来管理从数据库中获取的数据。对于连接池,我使用的是 HikariCP。
虽然第一个应用程序是 运行,但还有另一个应用程序正在更新数据库。
为连接池创建的数据源是否也会自动更新?如果没有,我该怎么做?我应该在每次数据库更新时创建一个新的连接池吗?
例如:
数据库中有一个学生的成绩记录。
为连接池创建了数据源。
比学生的成绩改变了。
如何更新数据源?
如有任何帮助,我们将不胜感激。谢谢你。
希望 this 消除您的困惑。
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.
无论您是否使用连接池,其他应用程序对数据库的更新都会正常发生,并且每次查询数据库时您都会看到新数据。你没必要'update the connection pool'
此图可能有助于您了解实际情况:
Java 所指的"DataSource" 是表示数据位置的抽象概念,而不是数据本身。您可以创建到一个数据源的多个连接,但您将只有该数据的一个副本,由数据库服务器控制。
如果您从一个应用程序更新数据,您就是通过连接向数据库服务器发送一条消息,以更改数据存储中保存的数据。提交的更改对任何其他应用程序都是立即可见的,因为它们都使用相同的数据库(即相同的物理数据存储)。
我是 运行 一个应用程序,它使用连接池来管理从数据库中获取的数据。对于连接池,我使用的是 HikariCP。
虽然第一个应用程序是 运行,但还有另一个应用程序正在更新数据库。 为连接池创建的数据源是否也会自动更新?如果没有,我该怎么做?我应该在每次数据库更新时创建一个新的连接池吗?
例如: 数据库中有一个学生的成绩记录。 为连接池创建了数据源。 比学生的成绩改变了。 如何更新数据源?
如有任何帮助,我们将不胜感激。谢谢你。
希望 this 消除您的困惑。
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.
无论您是否使用连接池,其他应用程序对数据库的更新都会正常发生,并且每次查询数据库时您都会看到新数据。你没必要'update the connection pool'
此图可能有助于您了解实际情况:
Java 所指的"DataSource" 是表示数据位置的抽象概念,而不是数据本身。您可以创建到一个数据源的多个连接,但您将只有该数据的一个副本,由数据库服务器控制。
如果您从一个应用程序更新数据,您就是通过连接向数据库服务器发送一条消息,以更改数据存储中保存的数据。提交的更改对任何其他应用程序都是立即可见的,因为它们都使用相同的数据库(即相同的物理数据存储)。