与 HikariCP 并发

Concurrency with HikariCP

我有一个 java 程序可以更新 oracle 数据库中的 table。

我已经尝试使用单个 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.