gpt4 book ai didi

java - 与 HikariCP 的并发

转载 作者:行者123 更新时间:2023-12-02 03:57:52 26 4
gpt4 key购买 nike

我有一个java程序,它更新oracle数据库中的表。

我已经尝试使用单个 JDBC 连接,但速度非常慢,需要几个小时才能完成。

我正在尝试使用 HikariCP 来创建连接池,并让多个线程从池中获取单独的连接。

假设池中有 6 个线程和 5 个数据库连接,其中 5 个线程调用 HikariDataSource.getConnection() 方法。他们每个人都会得到一个单独的数据库连接对象吗?

如果是,那么当线程调用 getConnection 方法或使用空连接执行剩余代码时,线程是否处于阻塞/等待状态?

如果没有,我如何让它们单独连接?

最佳答案

Will each of them get a separate db connection object?

每个线程请求连接,如果可用,则获取一个单独的数据库连接对象

If yes, then, will the thread be in blocked/ waiting state, when it calls the getConnection method or it executes the remaining code with a null connection?

如果没有可用的连接,它将等待连接被释放到池中并获取它,如果直到定义超时才获得连接,则会抛出超时异常

If no, how do I get them separate connections?

无关,因为每个线程都会获得不同的连接

关于HikariCP and concurrency :

HikariCP contains a custom lock-free collection called a ConcurrentBag. The idea was borrowed from the C# .NET ConcurrentBag class, but the internal implementation quite different. The ConcurrentBag provides...

  • A lock-free design
  • ThreadLocal caching
  • Queue-stealing
  • Direct hand-off optimizations

...resulting in a high degree of concurrency, extremely low latency, and minimized occurrences of false-sharing.

关于java - 与 HikariCP 的并发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53388228/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com