Java: JDBC Database connection pool

前端 未结 2 1770
借酒劲吻你
借酒劲吻你 2021-01-24 06:21

HI: I have a multi thread Java database application, we have to create a customized database pooling. The reason is that some of our preparedstatement has to be cached in the co

相关标签:
2条回答
  • 2021-01-24 06:52

    Using synchronized will cost you about 1-2 microseconds. If this is critical to you, you shouldn't be using JDBC. IMHO. Just accessing a service over a TCP connection is likely to cost 100 micro-seconds and many JDBC databases have a latency of 1-10 milli-seconds.

    I suspect that a few milliseconds per query/update is fine for you in which case using synchronization is unlikely to matter.

    Depending on how many threads you have, you can have a thread local connection for each thread. This reduces the overhead as much as possible.

    0 讨论(0)
  • 2021-01-24 06:57

    You have a multi-threaded application, but do many threads use the same database connection at the same time ? As the PreparedStatement cache will be done at the Connection level, if you connections are used by a single Thread at a time (which I think should be the case), you do not need synchronization.

    0 讨论(0)
提交回复
热议问题