How to handle database connection with multithreaded application. I have developed one application that created more 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 .?
-
1what do you mean by "it hangs"? Where does it hang? Do you have a stack trace / heap dump when it hangs?madhurtanwani– madhurtanwani2010-10-28 08:57:29 +00:00Commented Oct 28, 2010 at 8:57
-
my mean to say my application do nothing...? there is no exception or any memory leakage..... I thing i am suffer this for database connectionhirenb– hirenb2010-10-28 09:06:12 +00:00Commented Oct 28, 2010 at 9:06
-
What Database do you use? I know about some Memory-Leak Problems within the mySQL JDBC Driver. If your application start to slow down, it could be the memory-consumption.Christian Kuetbach– Christian Kuetbach2010-10-28 09:06:49 +00:00Commented Oct 28, 2010 at 9:06
-
yes i am using mysql JDBC driverhirenb– hirenb2010-10-28 09:19:55 +00:00Commented Oct 28, 2010 at 9:19
Add a comment
|
3 Answers
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?
2 Comments
hirenb
thank you .. madhur Actually i am using JDBC connection . and Create single connection for all threads. can i use like this public static synchronize Connection getConnection() instead of public static Connection getConnection()...........?
Qwerky
No - that won't work, it still allows two threads to access the Connection at the same time. You will have to write a wrapper class around your Connection that performs DB access and synchronize the whole class on the Connection.