Concurrency with HikariCP

uneq95 :

I have a java program which updates a table in oracle database.

I have tried it using a single JDBC connection and it's very slow and takes hours to complete.

I'm trying to use HikariCP to make a connection pool and have multiple threads get separate connections from the pool.

Suppose I have 6 threads and 5 database connections in the pool and 5 of the threads call the HikariDataSource.getConnection() method. 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?

user7294900 :

Will each of them get a separate db connection object?

Each thread ask connection, if available gets 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 available connection it will wait until connection is released to pool and take it, if it won't get connection until timeout defined, it will throw a timeout exception

If no, how do I get them separate connections?

Irrelevant, because each thread will get different connection

About 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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=102400&siteId=1