0

In my application,

I'll have to run >10000 threads at a time. These threads will perform some operations in DB. I'm using thread pool of size 100. The no of db connections is 10000, which is affecting the performance.

Is there any way i create few (say 50-100) db connections and share them among all the threads? Thanks in advance

Anil Kumar
  • 2,521
  • 7
  • 23
  • 40
  • Use a connection pool of size 100 (or less) as well? – Kayaman Jul 08 '15 at 13:03
  • Wait a minute... if you have a threadpool of 100 threads, how can you have over 10000 threads at a time? – Kayaman Jul 08 '15 at 13:10
  • 1
    You are pooling threads. So why not to pool connection to database too? See [this question](http://stackoverflow.com/questions/2835090/how-to-establish-a-connection-pool-in-jdbc). – plastique Jul 08 '15 at 13:13
  • Do you have 10,000 cpu cores? –  Jul 08 '15 at 13:17
  • It sounds like each thread maintains a database connection. Can you make your database connection short-lived? For example, in Hibernate, when you need to access the database, get an EntityManager, do the work, and then close the EntityManager. Your threads will then share the connections using the configured connection pool. – Jamie Jul 08 '15 at 13:24
  • @plastique, in apache-DBCP, how to limit the no of connections?. I am using the code as given in that link but it is not working – Anil Kumar Jul 09 '15 at 07:39

0 Answers0