Database connection with multithread in java
How to handle database connection with multithreaded application. I have developed one application that created mo开发者_JAVA技巧re thread. But when i run application it run correctly but after some time application is going to hang....?? what i have to do ..? How to handle Database connection with multithreaded application .?
You'll probably would like to use a connection pool. My recommendation is c3p0.
Database connections and threading need not be completely related.
Where are you fetching your DB connections from? Is it a central data source? Or a custom wrapper over JDBC connection? Or are you fetching it from a DB connection pool? Or are you creating a new connection in each thread?
Connection in the singular? If you only have one connection then you will have to synchronize your threads access to the connection. Better to use a Database connection pool though; almost all database vendors provide a connection pool implementation.
精彩评论